home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume9 / xterm / part03 < prev    next >
Encoding:
Internet Message Format  |  1987-04-20  |  59.0 KB

  1. Subject:  v09i056:  Terminal emulator for X window system, Part03/07
  2. Newsgroups: mod.sources
  3. Approved: rs@mirror.TMC.COM
  4.  
  5. Submitted by: edmoy%opal.Berkeley.EDU@berkeley.edu
  6. Mod.sources: Volume 9, Issue 56
  7. Archive-name: xterm6.6b/Part03
  8.  
  9. #! /bin/sh
  10. # This is a shell archive, meaning:
  11. # 1. Remove everything above the #! /bin/sh line.
  12. # 2. Save the resulting text in a file.
  13. # 3. Execute the file with /bin/sh (not csh) to create the files:
  14. #    VTparsetable.c button.c cursor.c
  15. if test -f VTparsetable.c
  16. then
  17.     echo shar: will not overwrite existing file "'VTparsetable.c'"
  18. else
  19. echo 'x - VTparsetable.c'
  20. cat << \RAZZLE!DAZZLE > VTparsetable.c
  21. /*
  22.  *    $Source: /u1/X/xterm/RCS/VTparsetable.c,v $
  23.  *    $Header: VTparsetable.c,v 10.101 86/12/01 21:49:52 jg Rel $
  24.  */
  25.  
  26. #ifndef lint
  27. static char *rcsid_VTparsetable_c = "$Header: VTparsetable.c,v 10.101 86/12/01 21:49:52 jg Rel $";
  28. #endif    lint
  29.  
  30. #include "VTparse.h"
  31. #ifndef lint
  32. static char sccs_id[] = "@(#)VTparsetable.c\tX10/6.6B\t12/26/86";
  33. #endif    lint
  34. /*
  35.  * Stupid Apollo C preprocessor can't handle long lines.  So... To keep
  36.  * it happy, we put each onto a seperate line....  Sigh...
  37.  */
  38.  
  39. int groundtable[] = {
  40. /*    NUL        SOH        STX        ETX    */
  41. CASE_IGNORE,
  42. CASE_IGNORE,
  43. CASE_IGNORE,
  44. CASE_IGNORE,
  45. /*    EOT        ENQ        ACK        BEL    */
  46. CASE_IGNORE,
  47. CASE_IGNORE,
  48. CASE_IGNORE,
  49. CASE_BELL,
  50. /*    BS        HT        NL        VT    */
  51. CASE_BS,
  52. CASE_TAB,
  53. CASE_VMOT,
  54. CASE_VMOT,
  55. /*    NP        CR        SO        SI    */
  56. CASE_VMOT,
  57. CASE_CR,
  58. CASE_SO,
  59. CASE_SI,
  60. /*    DLE        DC1        DC2        DC3    */
  61. CASE_IGNORE,
  62. CASE_IGNORE,
  63. CASE_IGNORE,
  64. CASE_IGNORE,
  65. /*    DC4        NAK        SYN        ETB    */
  66. CASE_IGNORE,
  67. CASE_IGNORE,
  68. CASE_IGNORE,
  69. CASE_IGNORE,
  70. /*    CAN        EM        SUB        ESC    */
  71. CASE_IGNORE,
  72. CASE_IGNORE,
  73. CASE_IGNORE,
  74. CASE_ESC,
  75. /*    FS        GS        RS        US    */
  76. CASE_IGNORE,
  77. CASE_IGNORE,
  78. CASE_IGNORE,
  79. CASE_IGNORE,
  80. /*    SP        !        "        #    */
  81. CASE_PRINT,
  82. CASE_PRINT,
  83. CASE_PRINT,
  84. CASE_PRINT,
  85. /*    $        %        &        '    */
  86. CASE_PRINT,
  87. CASE_PRINT,
  88. CASE_PRINT,
  89. CASE_PRINT,
  90. /*    (        )        *        +    */
  91. CASE_PRINT,
  92. CASE_PRINT,
  93. CASE_PRINT,
  94. CASE_PRINT,
  95. /*    ,        -        .        /    */
  96. CASE_PRINT,
  97. CASE_PRINT,
  98. CASE_PRINT,
  99. CASE_PRINT,
  100. /*    0        1        2        3    */
  101. CASE_PRINT,
  102. CASE_PRINT,
  103. CASE_PRINT,
  104. CASE_PRINT,
  105. /*    4        5        6        7    */
  106. CASE_PRINT,
  107. CASE_PRINT,
  108. CASE_PRINT,
  109. CASE_PRINT,
  110. /*    8        9        :        ;    */
  111. CASE_PRINT,
  112. CASE_PRINT,
  113. CASE_PRINT,
  114. CASE_PRINT,
  115. /*    <        =        >        ?    */
  116. CASE_PRINT,
  117. CASE_PRINT,
  118. CASE_PRINT,
  119. CASE_PRINT, 
  120. /*    @        A        B        C    */
  121. CASE_PRINT,
  122. CASE_PRINT,
  123. CASE_PRINT,
  124. CASE_PRINT,
  125. /*    D        E        F        G    */
  126. CASE_PRINT,
  127. CASE_PRINT,
  128. CASE_PRINT,
  129. CASE_PRINT,
  130. /*    H        I        J        K    */
  131. CASE_PRINT,
  132. CASE_PRINT,
  133. CASE_PRINT,
  134. CASE_PRINT,
  135. /*    L        M        N        O    */
  136. CASE_PRINT,
  137. CASE_PRINT,
  138. CASE_PRINT,
  139. CASE_PRINT,
  140. /*    P        Q        R        S    */
  141. CASE_PRINT,
  142. CASE_PRINT,
  143. CASE_PRINT,
  144. CASE_PRINT,
  145. /*    T        U        V        W    */
  146. CASE_PRINT,
  147. CASE_PRINT,
  148. CASE_PRINT,
  149. CASE_PRINT,
  150. /*    X        Y        Z        [    */
  151. CASE_PRINT,
  152. CASE_PRINT,
  153. CASE_PRINT,
  154. CASE_PRINT,
  155. /*    \        ]        ^        _    */
  156. CASE_PRINT,
  157. CASE_PRINT,
  158. CASE_PRINT,
  159. CASE_PRINT,
  160. /*    `        a        b        c    */
  161. CASE_PRINT,
  162. CASE_PRINT,
  163. CASE_PRINT,
  164. CASE_PRINT,
  165. /*    d        e        f        g    */
  166. CASE_PRINT,
  167. CASE_PRINT,
  168. CASE_PRINT,
  169. CASE_PRINT,
  170. /*    h        i        j        k    */
  171. CASE_PRINT,
  172. CASE_PRINT,
  173. CASE_PRINT,
  174. CASE_PRINT,
  175. /*    l        m        n        o    */
  176. CASE_PRINT,
  177. CASE_PRINT,
  178. CASE_PRINT,
  179. CASE_PRINT,
  180. /*    p        q        r        s    */
  181. CASE_PRINT,
  182. CASE_PRINT,
  183. CASE_PRINT,
  184. CASE_PRINT,
  185. /*    t        u        v        w    */
  186. CASE_PRINT,
  187. CASE_PRINT,
  188. CASE_PRINT,
  189. CASE_PRINT,
  190. /*    x        y        z        {    */
  191. CASE_PRINT,
  192. CASE_PRINT,
  193. CASE_PRINT,
  194. CASE_PRINT,
  195. /*    |        }        ~        DEL    */
  196. CASE_PRINT,
  197. CASE_PRINT,
  198. CASE_PRINT,
  199. CASE_GROUND_STATE, };  
  200.  
  201. int csitable[] = {
  202. /*    NUL        SOH        STX        ETX    */
  203. CASE_IGNORE,
  204. CASE_IGNORE,
  205. CASE_IGNORE,
  206. CASE_IGNORE,
  207. /*    EOT        ENQ        ACK        BEL    */
  208. CASE_IGNORE,
  209. CASE_IGNORE,
  210. CASE_IGNORE,
  211. CASE_BELL,
  212. /*    BS        HT        NL        VT    */
  213. CASE_BS,
  214. CASE_TAB,
  215. CASE_VMOT,
  216. CASE_VMOT,
  217. /*    NP        CR        SO        SI    */
  218. CASE_VMOT,
  219. CASE_CR,
  220. CASE_SO,
  221. CASE_SI,
  222. /*    DLE        DC1        DC2        DC3    */
  223. CASE_IGNORE,
  224. CASE_IGNORE,
  225. CASE_IGNORE,
  226. CASE_IGNORE,
  227. /*    DC4        NAK        SYN        ETB    */
  228. CASE_IGNORE,
  229. CASE_IGNORE,
  230. CASE_IGNORE,
  231. CASE_IGNORE,
  232. /*    CAN        EM        SUB        ESC    */
  233. CASE_IGNORE,
  234. CASE_IGNORE,
  235. CASE_IGNORE,
  236. CASE_ESC,
  237. /*    FS        GS        RS        US    */
  238. CASE_IGNORE,
  239. CASE_IGNORE,
  240. CASE_IGNORE,
  241. CASE_IGNORE,
  242. /*    SP        !        "        #    */
  243. CASE_ESC_IGNORE,
  244. CASE_ESC_IGNORE,
  245. CASE_ESC_IGNORE,
  246. CASE_ESC_IGNORE,
  247. /*    $        %        &        '    */
  248. CASE_ESC_IGNORE,
  249. CASE_ESC_IGNORE,
  250. CASE_ESC_IGNORE,
  251. CASE_ESC_IGNORE,
  252. /*    (        )        *        +    */
  253. CASE_ESC_IGNORE,
  254. CASE_ESC_IGNORE,
  255. CASE_ESC_IGNORE,
  256. CASE_ESC_IGNORE,
  257. /*    ,        -        .        /    */
  258. CASE_ESC_IGNORE,
  259. CASE_ESC_IGNORE,
  260. CASE_ESC_IGNORE,
  261. CASE_ESC_IGNORE,
  262. /*    0        1        2        3    */
  263. CASE_ESC_DIGIT,
  264. CASE_ESC_DIGIT,
  265. CASE_ESC_DIGIT,
  266. CASE_ESC_DIGIT,
  267. /*    4        5        6        7    */
  268. CASE_ESC_DIGIT,
  269. CASE_ESC_DIGIT,
  270. CASE_ESC_DIGIT,
  271. CASE_ESC_DIGIT,
  272. /*    8        9        :        ;    */
  273. CASE_ESC_DIGIT,
  274. CASE_ESC_DIGIT,
  275. CASE_IGNORE,
  276. CASE_ESC_SEMI,
  277. /*    <        =        >        ?    */
  278. CASE_IGNORE,
  279. CASE_IGNORE,
  280. CASE_IGNORE,
  281. CASE_DEC_STATE,
  282. /*    @        A        B        C    */
  283. CASE_ICH,
  284. CASE_CUU,
  285. CASE_CUD,
  286. CASE_CUF,
  287. /*    D        E        F        G    */
  288. CASE_CUB,
  289. CASE_GROUND_STATE,
  290. CASE_GROUND_STATE,
  291. CASE_GROUND_STATE,
  292. /*    H        I        J        K    */
  293. CASE_CUP,
  294. CASE_GROUND_STATE,
  295. CASE_ED,
  296. CASE_EL,
  297. /*    L        M        N        O    */
  298. CASE_IL,
  299. CASE_DL,
  300. CASE_GROUND_STATE,
  301. CASE_GROUND_STATE,
  302. /*    P        Q        R        S    */
  303. CASE_DCH,
  304. CASE_GROUND_STATE,
  305. CASE_GROUND_STATE,
  306. CASE_GROUND_STATE,
  307. /*    T        U        V        W    */
  308. CASE_GROUND_STATE,
  309. CASE_GROUND_STATE,
  310. CASE_GROUND_STATE,
  311. CASE_GROUND_STATE,
  312. /*    X        Y        Z        [    */
  313. CASE_GROUND_STATE,
  314. CASE_GROUND_STATE,
  315. CASE_GROUND_STATE,
  316. CASE_GROUND_STATE,
  317. /*    \        ]        ^        _    */
  318. CASE_GROUND_STATE,
  319. CASE_GROUND_STATE,
  320. CASE_GROUND_STATE,
  321. CASE_GROUND_STATE,
  322. /*    `        a        b        c    */
  323. CASE_GROUND_STATE,
  324. CASE_GROUND_STATE,
  325. CASE_GROUND_STATE,
  326. CASE_DA1,
  327. /*    d        e        f        g    */
  328. CASE_GROUND_STATE,
  329. CASE_GROUND_STATE,
  330. CASE_CUP,
  331. CASE_TBC,
  332. /*    h        i        j        k    */
  333. CASE_SET,
  334. CASE_GROUND_STATE,
  335. CASE_GROUND_STATE,
  336. CASE_GROUND_STATE,
  337. /*    l        m        n        o    */
  338. CASE_RST,
  339. CASE_SGR,
  340. CASE_CPR,
  341. CASE_GROUND_STATE,
  342. /*    p        q        r        s    */
  343. CASE_GROUND_STATE,
  344. CASE_GROUND_STATE,
  345. CASE_DECSTBM,
  346. CASE_GROUND_STATE,
  347. /*    t        u        v        w    */
  348. CASE_SUN_EMU,
  349. CASE_GROUND_STATE,
  350. CASE_GROUND_STATE,
  351. CASE_GROUND_STATE,
  352. /*    x        y        z        {    */
  353. CASE_DECREQTPARM,
  354. CASE_GROUND_STATE,
  355. CASE_GROUND_STATE,
  356. CASE_GROUND_STATE,
  357. /*    |        }        ~        DEL    */
  358. CASE_GROUND_STATE,
  359. CASE_GROUND_STATE,
  360. CASE_GROUND_STATE,
  361. CASE_GROUND_STATE,
  362. };
  363.  
  364. int dectable[] = {
  365. /*    NUL        SOH        STX        ETX    */
  366. CASE_IGNORE,
  367. CASE_IGNORE,
  368. CASE_IGNORE,
  369. CASE_IGNORE,
  370. /*    EOT        ENQ        ACK        BEL    */
  371. CASE_IGNORE,
  372. CASE_IGNORE,
  373. CASE_IGNORE,
  374. CASE_BELL,
  375. /*    BS        HT        NL        VT    */
  376. CASE_BS,
  377. CASE_TAB,
  378. CASE_VMOT,
  379. CASE_VMOT,
  380. /*    NP        CR        SO        SI    */
  381. CASE_VMOT,
  382. CASE_CR,
  383. CASE_SO,
  384. CASE_SI,
  385. /*    DLE        DC1        DC2        DC3    */
  386. CASE_IGNORE,
  387. CASE_IGNORE,
  388. CASE_IGNORE,
  389. CASE_IGNORE,
  390. /*    DC4        NAK        SYN        ETB    */
  391. CASE_IGNORE,
  392. CASE_IGNORE,
  393. CASE_IGNORE,
  394. CASE_IGNORE,
  395. /*    CAN        EM        SUB        ESC    */
  396. CASE_IGNORE,
  397. CASE_IGNORE,
  398. CASE_IGNORE,
  399. CASE_ESC,
  400. /*    FS        GS        RS        US    */
  401. CASE_IGNORE,
  402. CASE_IGNORE,
  403. CASE_IGNORE,
  404. CASE_IGNORE,
  405. /*    SP        !        "        #    */
  406. CASE_ESC_IGNORE,
  407. CASE_ESC_IGNORE,
  408. CASE_ESC_IGNORE,
  409. CASE_ESC_IGNORE,
  410. /*    $        %        &        '    */
  411. CASE_ESC_IGNORE,
  412. CASE_ESC_IGNORE,
  413. CASE_ESC_IGNORE,
  414. CASE_ESC_IGNORE,
  415. /*    (        )        *        +    */
  416. CASE_ESC_IGNORE,
  417. CASE_ESC_IGNORE,
  418. CASE_ESC_IGNORE,
  419. CASE_ESC_IGNORE,
  420. /*    ,        -        .        /    */
  421. CASE_ESC_IGNORE,
  422. CASE_ESC_IGNORE,
  423. CASE_ESC_IGNORE,
  424. CASE_ESC_IGNORE,
  425. /*    0        1        2        3    */
  426. CASE_ESC_DIGIT,
  427. CASE_ESC_DIGIT,
  428. CASE_ESC_DIGIT,
  429. CASE_ESC_DIGIT,
  430. /*    4        5        6        7    */
  431. CASE_ESC_DIGIT,
  432. CASE_ESC_DIGIT,
  433. CASE_ESC_DIGIT,
  434. CASE_ESC_DIGIT,
  435. /*    8        9        :        ;    */
  436. CASE_ESC_DIGIT,
  437. CASE_ESC_DIGIT,
  438. CASE_IGNORE,
  439. CASE_ESC_SEMI,
  440. /*    <        =        >        ?    */
  441. CASE_GROUND_STATE,
  442. CASE_GROUND_STATE,
  443. CASE_GROUND_STATE,
  444. CASE_GROUND_STATE,
  445. /*    @        A        B        C    */
  446. CASE_GROUND_STATE,
  447. CASE_GROUND_STATE,
  448. CASE_GROUND_STATE,
  449. CASE_GROUND_STATE,
  450. /*    D        E        F        G    */
  451. CASE_GROUND_STATE,
  452. CASE_ERASE_STATUS,
  453. CASE_FROM_STATUS,
  454. CASE_GROUND_STATE,
  455. /*    H        I        J        K    */
  456. CASE_HIDE_STATUS,
  457. CASE_GROUND_STATE,
  458. CASE_GROUND_STATE,
  459. CASE_GROUND_STATE,
  460. /*    L        M        N        O    */
  461. CASE_GROUND_STATE,
  462. CASE_GROUND_STATE,
  463. CASE_GROUND_STATE,
  464. CASE_GROUND_STATE,
  465. /*    P        Q        R        S    */
  466. CASE_GROUND_STATE,
  467. CASE_GROUND_STATE,
  468. CASE_GROUND_STATE,
  469. CASE_SHOW_STATUS,
  470. /*    T        U        V        W    */
  471. CASE_TO_STATUS,
  472. CASE_GROUND_STATE,
  473. CASE_GROUND_STATE,
  474. CASE_GROUND_STATE,
  475. /*    X        Y        Z        [    */
  476. CASE_GROUND_STATE,
  477. CASE_GROUND_STATE,
  478. CASE_GROUND_STATE,
  479. CASE_GROUND_STATE,
  480. /*    \        ]        ^        _    */
  481. CASE_GROUND_STATE,
  482. CASE_GROUND_STATE,
  483. CASE_GROUND_STATE,
  484. CASE_GROUND_STATE,
  485. /*    `        a        b        c    */
  486. CASE_GROUND_STATE,
  487. CASE_GROUND_STATE,
  488. CASE_GROUND_STATE,
  489. CASE_GROUND_STATE,
  490. /*    d        e        f        g    */
  491. CASE_GROUND_STATE,
  492. CASE_GROUND_STATE,
  493. CASE_GROUND_STATE,
  494. CASE_GROUND_STATE,
  495. /*    h        i        j        k    */
  496. CASE_DECSET,
  497. CASE_GROUND_STATE,
  498. CASE_GROUND_STATE,
  499. CASE_GROUND_STATE,
  500. /*    l        m        n        o    */
  501. CASE_DECRST,
  502. CASE_GROUND_STATE,
  503. CASE_GROUND_STATE,
  504. CASE_GROUND_STATE,
  505. /*    p        q        r        s    */
  506. CASE_GROUND_STATE,
  507. CASE_GROUND_STATE,
  508. CASE_XTERM_RESTORE,
  509. CASE_XTERM_SAVE,
  510. /*    t        u        v        w    */
  511. CASE_GROUND_STATE,
  512. CASE_GROUND_STATE,
  513. CASE_GROUND_STATE,
  514. CASE_GROUND_STATE,
  515. /*    x        y        z        {    */
  516. CASE_GROUND_STATE,
  517. CASE_GROUND_STATE,
  518. CASE_GROUND_STATE,
  519. CASE_GROUND_STATE,
  520. /*    |        }        ~        DEL    */
  521. CASE_GROUND_STATE,
  522. CASE_GROUND_STATE,
  523. CASE_GROUND_STATE,
  524. CASE_GROUND_STATE,
  525. };
  526.  
  527. int eigtable[] = {
  528. /*    NUL        SOH        STX        ETX    */
  529. CASE_IGNORE,
  530. CASE_IGNORE,
  531. CASE_IGNORE,
  532. CASE_IGNORE,
  533. /*    EOT        ENQ        ACK        BEL    */
  534. CASE_IGNORE,
  535. CASE_IGNORE,
  536. CASE_IGNORE,
  537. CASE_BELL,
  538. /*    BS        HT        NL        VT    */
  539. CASE_BS,
  540. CASE_TAB,
  541. CASE_VMOT,
  542. CASE_VMOT,
  543. /*    NP        CR        SO        SI    */
  544. CASE_VMOT,
  545. CASE_CR,
  546. CASE_SO,
  547. CASE_SI,
  548. /*    DLE        DC1        DC2        DC3    */
  549. CASE_IGNORE,
  550. CASE_IGNORE,
  551. CASE_IGNORE,
  552. CASE_IGNORE,
  553. /*    DC4        NAK        SYN        ETB    */
  554. CASE_IGNORE,
  555. CASE_IGNORE,
  556. CASE_IGNORE,
  557. CASE_IGNORE,
  558. /*    CAN        EM        SUB        ESC    */
  559. CASE_IGNORE,
  560. CASE_IGNORE,
  561. CASE_IGNORE,
  562. CASE_ESC,
  563. /*    FS        GS        RS        US    */
  564. CASE_IGNORE,
  565. CASE_IGNORE,
  566. CASE_IGNORE,
  567. CASE_IGNORE,
  568. /*    SP        !        "        #    */
  569. CASE_IGNORE,
  570. CASE_IGNORE,
  571. CASE_IGNORE,
  572. CASE_IGNORE,
  573. /*    $        %        &        '    */
  574. CASE_IGNORE,
  575. CASE_IGNORE,
  576. CASE_IGNORE,
  577. CASE_IGNORE,
  578. /*    (        )        *        +    */
  579. CASE_IGNORE,
  580. CASE_IGNORE,
  581. CASE_IGNORE,
  582. CASE_IGNORE,
  583. /*    ,
  584.     -        .        /    */
  585. CASE_IGNORE,
  586. CASE_IGNORE,
  587. CASE_IGNORE,
  588. CASE_IGNORE,
  589. /*    0        1        2        3    */
  590. CASE_GROUND_STATE,
  591. CASE_GROUND_STATE,
  592. CASE_GROUND_STATE,
  593. CASE_GROUND_STATE,
  594. /*    4        5        6        7    */
  595. CASE_GROUND_STATE,
  596. CASE_GROUND_STATE,
  597. CASE_GROUND_STATE,
  598. CASE_GROUND_STATE,
  599. /*    8        9        :        ;    */
  600. CASE_GROUND_STATE,
  601. CASE_GROUND_STATE,
  602. CASE_GROUND_STATE,
  603. CASE_GROUND_STATE,
  604. /*    <        =        >        ?    */
  605. CASE_GROUND_STATE,
  606. CASE_GROUND_STATE,
  607. CASE_GROUND_STATE,
  608. CASE_GROUND_STATE,
  609. /*    @        A        B        C    */
  610. CASE_GROUND_STATE,
  611. CASE_GROUND_STATE,
  612. CASE_GROUND_STATE,
  613. CASE_GROUND_STATE,
  614. /*    D        E        F        G    */
  615. CASE_GROUND_STATE,
  616. CASE_GROUND_STATE,
  617. CASE_GROUND_STATE,
  618. CASE_GROUND_STATE,
  619. /*    H        I        J        K    */
  620. CASE_GROUND_STATE,
  621. CASE_GROUND_STATE,
  622. CASE_GROUND_STATE,
  623. CASE_GROUND_STATE,
  624. /*    L        M        N        O    */
  625. CASE_GROUND_STATE,
  626. CASE_GROUND_STATE,
  627. CASE_GROUND_STATE,
  628. CASE_GROUND_STATE,
  629. /*    P        Q        R        S    */
  630. CASE_GROUND_STATE,
  631. CASE_GROUND_STATE,
  632. CASE_GROUND_STATE,
  633. CASE_GROUND_STATE,
  634. /*    T        U        V        W    */
  635. CASE_GROUND_STATE,
  636. CASE_GROUND_STATE,
  637. CASE_GROUND_STATE,
  638. CASE_GROUND_STATE,
  639. /*    X        Y        Z        [    */
  640. CASE_GROUND_STATE,
  641. CASE_GROUND_STATE,
  642. CASE_GROUND_STATE,
  643. CASE_GROUND_STATE,
  644. /*    \        ]        ^        _    */
  645. CASE_GROUND_STATE,
  646. CASE_GROUND_STATE,
  647. CASE_GROUND_STATE,
  648. CASE_GROUND_STATE,
  649. /*    `        a        b        c    */
  650. CASE_GROUND_STATE,
  651. CASE_GROUND_STATE,
  652. CASE_GROUND_STATE,
  653. CASE_GROUND_STATE,
  654. /*    d        e        f        g    */
  655. CASE_GROUND_STATE,
  656. CASE_GROUND_STATE,
  657. CASE_GROUND_STATE,
  658. CASE_GROUND_STATE,
  659. /*    h        i        j        k    */
  660. CASE_GROUND_STATE,
  661. CASE_GROUND_STATE,
  662. CASE_GROUND_STATE,
  663. CASE_GROUND_STATE,
  664. /*    l        m        n        o    */
  665. CASE_GROUND_STATE,
  666. CASE_GROUND_STATE,
  667. CASE_GROUND_STATE,
  668. CASE_GROUND_STATE,
  669. /*    p        q        r        s    */
  670. CASE_GROUND_STATE,
  671. CASE_GROUND_STATE,
  672. CASE_GROUND_STATE,
  673. CASE_GROUND_STATE,
  674. /*    t        u        v        w    */
  675. CASE_GROUND_STATE,
  676. CASE_GROUND_STATE,
  677. CASE_GROUND_STATE,
  678. CASE_GROUND_STATE,
  679. /*    x        y        z        {    */
  680. CASE_GROUND_STATE,
  681. CASE_GROUND_STATE,
  682. CASE_GROUND_STATE,
  683. CASE_GROUND_STATE,
  684. /*    |        }        ~        DEL    */
  685. CASE_GROUND_STATE,
  686. CASE_GROUND_STATE,
  687. CASE_GROUND_STATE,
  688. CASE_GROUND_STATE,
  689. };
  690.  
  691. int esctable[] = {
  692. /*    NUL        SOH        STX        ETX    */
  693. CASE_IGNORE,
  694. CASE_IGNORE,
  695. CASE_IGNORE,
  696. CASE_IGNORE,
  697. /*    EOT        ENQ        ACK        BEL    */
  698. CASE_IGNORE,
  699. CASE_IGNORE,
  700. CASE_IGNORE,
  701. CASE_BELL,
  702. /*    BS        HT        NL        VT    */
  703. CASE_BS,
  704. CASE_TAB,
  705. CASE_VMOT,
  706. CASE_VMOT,
  707. /*    NP        CR        SO        SI    */
  708. CASE_VMOT,
  709. CASE_CR,
  710. CASE_SO,
  711. CASE_SI,
  712. /*    DLE        DC1        DC2        DC3    */
  713. CASE_IGNORE,
  714. CASE_IGNORE,
  715. CASE_IGNORE,
  716. CASE_IGNORE,
  717. /*    DC4        NAK        SYN        ETB    */
  718. CASE_IGNORE,
  719. CASE_IGNORE,
  720. CASE_IGNORE,
  721. CASE_IGNORE,
  722. /*    CAN        EM        SUB        ESC    */
  723. CASE_IGNORE,
  724. CASE_IGNORE,
  725. CASE_IGNORE,
  726. CASE_ESC,
  727. /*    FS        GS        RS        US    */
  728. CASE_IGNORE,
  729. CASE_IGNORE,
  730. CASE_IGNORE,
  731. CASE_IGNORE,
  732. /*    SP        !        "        #    */
  733. CASE_ESC_IGNORE,
  734. CASE_ESC_IGNORE,
  735. CASE_ESC_IGNORE,
  736. CASE_SCR_STATE,
  737. /*    $        %        &        '    */
  738. CASE_ESC_IGNORE,
  739. CASE_ESC_IGNORE,
  740. CASE_ESC_IGNORE,
  741. CASE_ESC_IGNORE,
  742. /*    (        )        *        +    */
  743. CASE_SCS0_STATE,
  744. CASE_SCS1_STATE,
  745. CASE_SCS2_STATE,
  746. CASE_SCS3_STATE,
  747. /*    ,        -        .        /    */
  748. CASE_ESC_IGNORE,
  749. CASE_ESC_IGNORE,
  750. CASE_ESC_IGNORE,
  751. CASE_ESC_IGNORE,
  752. /*    0        1        2        3    */
  753. CASE_GROUND_STATE,
  754. CASE_GROUND_STATE,
  755. CASE_GROUND_STATE,
  756. CASE_GROUND_STATE,
  757. /*    4        5        6        7    */
  758. CASE_GROUND_STATE,
  759. CASE_GROUND_STATE,
  760. CASE_GROUND_STATE,
  761. CASE_DECSC,
  762. /*    8        9        :        ;    */
  763. CASE_DECRC,
  764. CASE_GROUND_STATE,
  765. CASE_GROUND_STATE,
  766. CASE_GROUND_STATE,
  767. /*    <        =        >        ?    */
  768. CASE_GROUND_STATE,
  769. CASE_DECKPAM,
  770. CASE_DECKPNM,
  771. CASE_GROUND_STATE,
  772. /*    @        A        B        C    */
  773. CASE_GROUND_STATE,
  774. CASE_GROUND_STATE,
  775. CASE_GROUND_STATE,
  776. CASE_GROUND_STATE,
  777. /*    D        E        F        G    */
  778. CASE_IND,
  779. CASE_NEL,
  780. CASE_GROUND_STATE,
  781. CASE_GROUND_STATE,
  782. /*    H        I        J        K    */
  783. CASE_HTS,
  784. CASE_GROUND_STATE,
  785. CASE_GROUND_STATE,
  786. CASE_GROUND_STATE,
  787. /*    L        M        N        O    */
  788. CASE_GROUND_STATE,
  789. CASE_RI,
  790. CASE_SS2,
  791. CASE_SS3,
  792. /*    P        Q        R        S    */
  793. CASE_IGNORE_STATE,
  794. CASE_GROUND_STATE,
  795. CASE_GROUND_STATE,
  796. CASE_GROUND_STATE,
  797. /*    T        U        V        W    */
  798. CASE_GROUND_STATE,
  799. CASE_GROUND_STATE,
  800. CASE_GROUND_STATE,
  801. CASE_GROUND_STATE,
  802. /*    X        Y        Z        [    */
  803. CASE_GROUND_STATE,
  804. CASE_GROUND_STATE,
  805. CASE_GROUND_STATE,
  806. CASE_CSI_STATE,
  807. /*    \        ]        ^        _    */
  808. CASE_GROUND_STATE,
  809. CASE_OSC,
  810. CASE_IGNORE_STATE,
  811. CASE_IGNORE_STATE,
  812. /*    `        a        b        c    */
  813. CASE_GROUND_STATE,
  814. CASE_GROUND_STATE,
  815. CASE_GROUND_STATE,
  816. CASE_RIS,
  817. /*    d        e        f        g    */
  818. CASE_GROUND_STATE,
  819. CASE_GROUND_STATE,
  820. CASE_GROUND_STATE,
  821. CASE_GROUND_STATE,
  822. /*    h        i        j        k    */
  823. CASE_GROUND_STATE,
  824. CASE_GROUND_STATE,
  825. CASE_GROUND_STATE,
  826. CASE_GROUND_STATE,
  827. /*    l        m        n        o    */
  828. CASE_GROUND_STATE,
  829. CASE_GROUND_STATE,
  830. CASE_LS2,
  831. CASE_LS3,
  832. /*    p        q        r        s    */
  833. CASE_GROUND_STATE,
  834. CASE_GROUND_STATE,
  835. CASE_GROUND_STATE,
  836. CASE_GROUND_STATE,
  837. /*    t        u        v        w    */
  838. CASE_GROUND_STATE,
  839. CASE_GROUND_STATE,
  840. CASE_GROUND_STATE,
  841. CASE_GROUND_STATE,
  842. /*    x        y        z        {    */
  843. CASE_GROUND_STATE,
  844. CASE_GROUND_STATE,
  845. CASE_GROUND_STATE,
  846. CASE_GROUND_STATE,
  847. /*    |        }        ~        DEL    */
  848. CASE_LS3R,
  849. CASE_LS2R,
  850. CASE_LS1R,
  851. CASE_GROUND_STATE,
  852. };
  853.  
  854. int iestable[] = {
  855. /*    NUL        SOH        STX        ETX    */
  856. CASE_IGNORE_STATE,
  857. CASE_IGNORE_STATE,
  858. CASE_IGNORE_STATE,
  859. CASE_IGNORE_STATE,
  860. /*    EOT        ENQ        ACK        BEL    */
  861. CASE_IGNORE_STATE,
  862. CASE_IGNORE_STATE,
  863. CASE_IGNORE_STATE,
  864. CASE_IGNORE_STATE,
  865. /*    BS        HT        NL        VT    */
  866. CASE_IGNORE_STATE,
  867. CASE_IGNORE_STATE,
  868. CASE_IGNORE_STATE,
  869. CASE_IGNORE_STATE,
  870. /*    NP        CR        SO        SI    */
  871. CASE_IGNORE_STATE,
  872. CASE_IGNORE_STATE,
  873. CASE_IGNORE_STATE,
  874. CASE_IGNORE_STATE,
  875. /*    DLE        DC1        DC2        DC3    */
  876. CASE_IGNORE_STATE,
  877. CASE_IGNORE_STATE,
  878. CASE_IGNORE_STATE,
  879. CASE_IGNORE_STATE,
  880. /*    DC4        NAK        SYN        ETB    */
  881. CASE_IGNORE_STATE,
  882. CASE_IGNORE_STATE,
  883. CASE_IGNORE_STATE,
  884. CASE_IGNORE_STATE,
  885. /*    CAN        EM        SUB        ESC    */
  886. CASE_IGNORE_STATE,
  887. CASE_IGNORE_STATE,
  888. CASE_IGNORE_STATE,
  889. CASE_IGNORE_STATE,
  890. /*    FS        GS        RS        US    */
  891. CASE_IGNORE_STATE,
  892. CASE_IGNORE_STATE,
  893. CASE_IGNORE_STATE,
  894. CASE_IGNORE_STATE,
  895. /*    SP        !        "        #    */
  896. CASE_IGNORE_STATE,
  897. CASE_IGNORE_STATE,
  898. CASE_IGNORE_STATE,
  899. CASE_IGNORE_STATE,
  900. /*    $        %        &        '    */
  901. CASE_IGNORE_STATE,
  902. CASE_IGNORE_STATE,
  903. CASE_IGNORE_STATE,
  904. CASE_IGNORE_STATE,
  905. /*    (        )        *        +    */
  906. CASE_IGNORE_STATE,
  907. CASE_IGNORE_STATE,
  908. CASE_IGNORE_STATE,
  909. CASE_IGNORE_STATE,
  910. /*    ,        -        .        /    */
  911. CASE_IGNORE_STATE,
  912. CASE_IGNORE_STATE,
  913. CASE_IGNORE_STATE,
  914. CASE_IGNORE_STATE,
  915. /*    0        1        2        3    */
  916. CASE_IGNORE_STATE,
  917. CASE_IGNORE_STATE,
  918. CASE_IGNORE_STATE,
  919. CASE_IGNORE_STATE,
  920. /*    4        5        6        7    */
  921. CASE_IGNORE_STATE,
  922. CASE_IGNORE_STATE,
  923. CASE_IGNORE_STATE,
  924. CASE_IGNORE_STATE,
  925. /*    8        9        :        ;    */
  926. CASE_IGNORE_STATE,
  927. CASE_IGNORE_STATE,
  928. CASE_IGNORE_STATE,
  929. CASE_IGNORE_STATE,
  930. /*    <        =        >        ?    */
  931. CASE_IGNORE_STATE,
  932. CASE_IGNORE_STATE,
  933. CASE_IGNORE_STATE,
  934. CASE_IGNORE_STATE,
  935. /*    @        A        B        C    */
  936. CASE_IGNORE_STATE,
  937. CASE_IGNORE_STATE,
  938. CASE_IGNORE_STATE,
  939. CASE_IGNORE_STATE,
  940. /*    D        E        F        G    */
  941. CASE_IGNORE_STATE,
  942. CASE_IGNORE_STATE,
  943. CASE_IGNORE_STATE,
  944. CASE_IGNORE_STATE,
  945. /*    H        I        J        K    */
  946. CASE_IGNORE_STATE,
  947. CASE_IGNORE_STATE,
  948. CASE_IGNORE_STATE,
  949. CASE_IGNORE_STATE,
  950. /*    L        M        N        O    */
  951. CASE_IGNORE_STATE,
  952. CASE_IGNORE_STATE,
  953. CASE_IGNORE_STATE,
  954. CASE_IGNORE_STATE,
  955. /*    P        Q        R        S    */
  956. CASE_IGNORE_STATE,
  957. CASE_IGNORE_STATE,
  958. CASE_IGNORE_STATE,
  959. CASE_IGNORE_STATE,
  960. /*    T        U        V        W    */
  961. CASE_IGNORE_STATE,
  962. CASE_IGNORE_STATE,
  963. CASE_IGNORE_STATE,
  964. CASE_IGNORE_STATE,
  965. /*    X        Y        Z        [    */
  966. CASE_IGNORE_STATE,
  967. CASE_IGNORE_STATE,
  968. CASE_IGNORE_STATE,
  969. CASE_IGNORE_STATE,
  970. /*    \        ]        ^        _    */
  971. CASE_GROUND_STATE,
  972. CASE_IGNORE_STATE,
  973. CASE_IGNORE_STATE,
  974. CASE_IGNORE_STATE,
  975. /*    `        a        b        c    */
  976. CASE_IGNORE_STATE,
  977. CASE_IGNORE_STATE,
  978. CASE_IGNORE_STATE,
  979. CASE_IGNORE_STATE,
  980. /*    d        e        f        g    */
  981. CASE_IGNORE_STATE,
  982. CASE_IGNORE_STATE,
  983. CASE_IGNORE_STATE,
  984. CASE_IGNORE_STATE,
  985. /*    h        i        j        k    */
  986. CASE_IGNORE_STATE,
  987. CASE_IGNORE_STATE,
  988. CASE_IGNORE_STATE,
  989. CASE_IGNORE_STATE,
  990. /*    l        m        n        o    */
  991. CASE_IGNORE_STATE,
  992. CASE_IGNORE_STATE,
  993. CASE_IGNORE_STATE,
  994. CASE_IGNORE_STATE,
  995. /*    p        q        r        s    */
  996. CASE_IGNORE_STATE,
  997. CASE_IGNORE_STATE,
  998. CASE_IGNORE_STATE,
  999. CASE_IGNORE_STATE,
  1000. /*    t        u        v        w    */
  1001. CASE_IGNORE_STATE,
  1002. CASE_IGNORE_STATE,
  1003. CASE_IGNORE_STATE,
  1004. CASE_IGNORE_STATE,
  1005. /*    x        y        z        {    */
  1006. CASE_IGNORE_STATE,
  1007. CASE_IGNORE_STATE,
  1008. CASE_IGNORE_STATE,
  1009. CASE_IGNORE_STATE,
  1010. /*    |        }        ~        DEL    */
  1011. CASE_IGNORE_STATE,
  1012. CASE_IGNORE_STATE,
  1013. CASE_IGNORE_STATE,
  1014. CASE_IGNORE_STATE,
  1015. };
  1016.  
  1017. int igntable[] = {
  1018. /*    NUL        SOH        STX        ETX    */
  1019. CASE_IGNORE,
  1020. CASE_IGNORE,
  1021. CASE_IGNORE,
  1022. CASE_IGNORE,
  1023. /*    EOT        ENQ        ACK        BEL    */
  1024. CASE_IGNORE,
  1025. CASE_IGNORE,
  1026. CASE_IGNORE,
  1027. CASE_IGNORE,
  1028. /*    BS        HT        NL        VT    */
  1029. CASE_IGNORE,
  1030. CASE_IGNORE,
  1031. CASE_IGNORE,
  1032. CASE_IGNORE,
  1033. /*    NP        CR        SO        SI    */
  1034. CASE_IGNORE,
  1035. CASE_IGNORE,
  1036. CASE_IGNORE,
  1037. CASE_IGNORE,
  1038. /*    DLE        DC1        DC2        DC3    */
  1039. CASE_IGNORE,
  1040. CASE_IGNORE,
  1041. CASE_IGNORE,
  1042. CASE_IGNORE,
  1043. /*    DC4        NAK        SYN        ETB    */
  1044. CASE_IGNORE,
  1045. CASE_IGNORE,
  1046. CASE_IGNORE,
  1047. CASE_IGNORE,
  1048. /*    CAN        EM        SUB        ESC    */
  1049. CASE_GROUND_STATE, 
  1050. CASE_IGNORE,
  1051. CASE_GROUND_STATE,
  1052. CASE_IGNORE_ESC,
  1053. /*    FS        GS        RS        US    */
  1054. CASE_IGNORE,
  1055. CASE_IGNORE,
  1056. CASE_IGNORE,
  1057. CASE_IGNORE,
  1058. /*    SP        !        "        #    */
  1059. CASE_IGNORE,
  1060. CASE_IGNORE,
  1061. CASE_IGNORE,
  1062. CASE_IGNORE,
  1063. /*    $        %        &        '    */
  1064. CASE_IGNORE,
  1065. CASE_IGNORE,
  1066. CASE_IGNORE,
  1067. CASE_IGNORE,
  1068. /*    (        )        *        +    */
  1069. CASE_IGNORE,
  1070. CASE_IGNORE,
  1071. CASE_IGNORE,
  1072. CASE_IGNORE,
  1073. /*    ,        -        .        /    */
  1074. CASE_IGNORE,
  1075. CASE_IGNORE,
  1076. CASE_IGNORE,
  1077. CASE_IGNORE,
  1078. /*    0        1        2        3    */
  1079. CASE_IGNORE,
  1080. CASE_IGNORE,
  1081. CASE_IGNORE,
  1082. CASE_IGNORE,
  1083. /*    4        5        6        7    */
  1084. CASE_IGNORE,
  1085. CASE_IGNORE,
  1086. CASE_IGNORE,
  1087. CASE_IGNORE,
  1088. /*    8        9        :        ;    */
  1089. CASE_IGNORE,
  1090. CASE_IGNORE,
  1091. CASE_IGNORE,
  1092. CASE_IGNORE,
  1093. /*    <        =        >        ?    */
  1094. CASE_IGNORE,
  1095. CASE_IGNORE,
  1096. CASE_IGNORE,
  1097. CASE_IGNORE,
  1098. /*    @        A        B        C    */
  1099. CASE_IGNORE,
  1100. CASE_IGNORE,
  1101. CASE_IGNORE,
  1102. CASE_IGNORE,
  1103. /*    D        E        F        G    */
  1104. CASE_IGNORE,
  1105. CASE_IGNORE,
  1106. CASE_IGNORE,
  1107. CASE_IGNORE,
  1108. /*    H        I        J        K    */
  1109. CASE_IGNORE,
  1110. CASE_IGNORE,
  1111. CASE_IGNORE,
  1112. CASE_IGNORE,
  1113. /*    L        M        N        O    */
  1114. CASE_IGNORE,
  1115. CASE_IGNORE,
  1116. CASE_IGNORE,
  1117. CASE_IGNORE,
  1118. /*    P        Q        R        S    */
  1119. CASE_IGNORE,
  1120. CASE_IGNORE,
  1121. CASE_IGNORE,
  1122. CASE_IGNORE,
  1123. /*    T        U        V        W    */
  1124. CASE_IGNORE,
  1125. CASE_IGNORE,
  1126. CASE_IGNORE,
  1127. CASE_IGNORE,
  1128. /*    X        Y        Z        [    */
  1129. CASE_IGNORE,
  1130. CASE_IGNORE,
  1131. CASE_IGNORE,
  1132. CASE_IGNORE,
  1133. /*    \        ]        ^        _    */
  1134. CASE_IGNORE,
  1135. CASE_IGNORE,
  1136. CASE_IGNORE,
  1137. CASE_IGNORE,
  1138. /*    `        a        b        c    */
  1139. CASE_IGNORE,
  1140. CASE_IGNORE,
  1141. CASE_IGNORE,
  1142. CASE_IGNORE,
  1143. /*    d        e        f        g    */
  1144. CASE_IGNORE,
  1145. CASE_IGNORE,
  1146. CASE_IGNORE,
  1147. CASE_IGNORE,
  1148. /*    h        i        j        k    */
  1149. CASE_IGNORE,
  1150. CASE_IGNORE,
  1151. CASE_IGNORE,
  1152. CASE_IGNORE,
  1153. /*    l        m        n        o    */
  1154. CASE_IGNORE,
  1155. CASE_IGNORE,
  1156. CASE_IGNORE,
  1157. CASE_IGNORE,
  1158. /*    p        q        r        s    */
  1159. CASE_IGNORE,
  1160. CASE_IGNORE,
  1161. CASE_IGNORE,
  1162. CASE_IGNORE,
  1163. /*    t        u        v        w    */
  1164. CASE_IGNORE,
  1165. CASE_IGNORE,
  1166. CASE_IGNORE,
  1167. CASE_IGNORE,
  1168. /*    x        y        z        {    */
  1169. CASE_IGNORE,
  1170. CASE_IGNORE,
  1171. CASE_IGNORE,
  1172. CASE_IGNORE,
  1173. /*    |        }        ~        DEL    */
  1174. CASE_IGNORE,
  1175. CASE_IGNORE,
  1176. CASE_IGNORE,
  1177. CASE_IGNORE,
  1178. };
  1179.  
  1180. int scrtable[] = {
  1181. /*    NUL        SOH        STX        ETX    */
  1182. CASE_IGNORE,
  1183. CASE_IGNORE,
  1184. CASE_IGNORE,
  1185. CASE_IGNORE,
  1186. /*    EOT        ENQ        ACK        BEL    */
  1187. CASE_IGNORE,
  1188. CASE_IGNORE,
  1189. CASE_IGNORE,
  1190. CASE_BELL,
  1191. /*    BS        HT        NL        VT    */
  1192. CASE_BS,
  1193. CASE_TAB,
  1194. CASE_VMOT,
  1195. CASE_VMOT,
  1196. /*    NP        CR        SO        SI    */
  1197. CASE_VMOT,
  1198. CASE_CR,
  1199. CASE_SO,
  1200. CASE_SI,
  1201. /*    DLE        DC1        DC2        DC3    */
  1202. CASE_IGNORE,
  1203. CASE_IGNORE,
  1204. CASE_IGNORE,
  1205. CASE_IGNORE,
  1206. /*    DC4        NAK        SYN        ETB    */
  1207. CASE_IGNORE,
  1208. CASE_IGNORE,
  1209. CASE_IGNORE,
  1210. CASE_IGNORE,
  1211. /*    CAN        EM        SUB        ESC    */
  1212. CASE_IGNORE,
  1213. CASE_IGNORE,
  1214. CASE_IGNORE,
  1215. CASE_ESC,
  1216. /*    FS        GS        RS        US    */
  1217. CASE_IGNORE,
  1218. CASE_IGNORE,
  1219. CASE_IGNORE,
  1220. CASE_IGNORE,
  1221. /*    SP        !        "        #    */
  1222. CASE_ESC_IGNORE,
  1223. CASE_ESC_IGNORE,
  1224. CASE_ESC_IGNORE,
  1225. CASE_ESC_IGNORE,
  1226. /*    $        %        &        '    */
  1227. CASE_ESC_IGNORE,
  1228. CASE_ESC_IGNORE,
  1229. CASE_ESC_IGNORE,
  1230. CASE_ESC_IGNORE,
  1231. /*    (        )        *        +    */
  1232. CASE_ESC_IGNORE,
  1233. CASE_ESC_IGNORE,
  1234. CASE_ESC_IGNORE,
  1235. CASE_ESC_IGNORE,
  1236. /*    ,        -        .        /    */
  1237. CASE_ESC_IGNORE,
  1238. CASE_ESC_IGNORE,
  1239. CASE_ESC_IGNORE,
  1240. CASE_ESC_IGNORE,
  1241. /*    0        1        2        3    */
  1242. CASE_GROUND_STATE,
  1243. CASE_HIDDEN,
  1244. CASE_GROUND_STATE,
  1245. CASE_GROUND_STATE,
  1246. /*    4        5        6        7    */
  1247. CASE_GROUND_STATE,
  1248. CASE_GROUND_STATE,
  1249. CASE_GROUND_STATE,
  1250. CASE_GROUND_STATE,
  1251. /*    8        9        :        ;    */
  1252. CASE_DECALN,
  1253. CASE_GROUND_STATE,
  1254. CASE_GROUND_STATE,
  1255. CASE_GROUND_STATE,
  1256. /*    <        =        >        ?    */
  1257. CASE_GROUND_STATE,
  1258. CASE_GROUND_STATE,
  1259. CASE_GROUND_STATE,
  1260. CASE_GROUND_STATE,
  1261. /*    @        A        B        C    */
  1262. CASE_GROUND_STATE,
  1263. CASE_GROUND_STATE,
  1264. CASE_GROUND_STATE,
  1265. CASE_GROUND_STATE,
  1266. /*    D        E        F        G    */
  1267. CASE_GROUND_STATE,
  1268. CASE_GROUND_STATE,
  1269. CASE_GROUND_STATE,
  1270. CASE_GROUND_STATE,
  1271. /*    H        I        J        K    */
  1272. CASE_GROUND_STATE,
  1273. CASE_GROUND_STATE,
  1274. CASE_GROUND_STATE,
  1275. CASE_GROUND_STATE,
  1276. /*    L        M        N        O    */
  1277. CASE_GROUND_STATE,
  1278. CASE_GROUND_STATE,
  1279. CASE_GROUND_STATE,
  1280. CASE_GROUND_STATE,
  1281. /*    P        Q        R        S    */
  1282. CASE_GROUND_STATE,
  1283. CASE_GROUND_STATE,
  1284. CASE_GROUND_STATE,
  1285. CASE_GROUND_STATE,
  1286. /*    T        U        V        W    */
  1287. CASE_GROUND_STATE,
  1288. CASE_GROUND_STATE,
  1289. CASE_GROUND_STATE,
  1290. CASE_GROUND_STATE,
  1291. /*    X        Y        Z        [    */
  1292. CASE_GROUND_STATE,
  1293. CASE_GROUND_STATE,
  1294. CASE_GROUND_STATE,
  1295. CASE_GROUND_STATE,
  1296. /*    \        ]        ^        _    */
  1297. CASE_GROUND_STATE,
  1298. CASE_GROUND_STATE,
  1299. CASE_GROUND_STATE,
  1300. CASE_GROUND_STATE,
  1301. /*    `        a        b        c    */
  1302. CASE_GROUND_STATE,
  1303. CASE_GROUND_STATE,
  1304. CASE_GROUND_STATE,
  1305. CASE_GROUND_STATE,
  1306. /*    d        e        f        g    */
  1307. CASE_GROUND_STATE,
  1308. CASE_GROUND_STATE,
  1309. CASE_GROUND_STATE,
  1310. CASE_GROUND_STATE,
  1311. /*    h        i        j        k    */
  1312. CASE_GROUND_STATE,
  1313. CASE_GROUND_STATE,
  1314. CASE_GROUND_STATE,
  1315. CASE_GROUND_STATE,
  1316. /*    l        m        n        o    */
  1317. CASE_GROUND_STATE,
  1318. CASE_GROUND_STATE,
  1319. CASE_GROUND_STATE,
  1320. CASE_GROUND_STATE,
  1321. /*    p        q        r        s    */
  1322. CASE_GROUND_STATE,
  1323. CASE_GROUND_STATE,
  1324. CASE_GROUND_STATE,
  1325. CASE_GROUND_STATE,
  1326. /*    t        u        v        w    */
  1327. CASE_GROUND_STATE,
  1328. CASE_GROUND_STATE,
  1329. CASE_GROUND_STATE,
  1330. CASE_GROUND_STATE,
  1331. /*    x        y        z        {    */
  1332. CASE_GROUND_STATE,
  1333. CASE_GROUND_STATE,
  1334. CASE_GROUND_STATE,
  1335. CASE_GROUND_STATE,
  1336. /*    |        }        ~        DEL    */
  1337. CASE_GROUND_STATE,
  1338. CASE_GROUND_STATE,
  1339. CASE_GROUND_STATE,
  1340. CASE_GROUND_STATE,
  1341. };
  1342.  
  1343. int scstable[] = {
  1344. /*    NUL        SOH        STX        ETX    */
  1345. CASE_IGNORE,
  1346. CASE_IGNORE,
  1347. CASE_IGNORE,
  1348. CASE_IGNORE,
  1349. /*    EOT        ENQ        ACK        BEL    */
  1350. CASE_IGNORE,
  1351. CASE_IGNORE,
  1352. CASE_IGNORE,
  1353. CASE_BELL,
  1354. /*    BS        HT        NL        VT    */
  1355. CASE_BS,
  1356. CASE_TAB,
  1357. CASE_VMOT,
  1358. CASE_VMOT,
  1359. /*    NP        CR        SO        SI    */
  1360. CASE_VMOT,
  1361. CASE_CR,
  1362. CASE_SO,
  1363. CASE_SI,
  1364. /*    DLE        DC1        DC2        DC3    */
  1365. CASE_IGNORE,
  1366. CASE_IGNORE,
  1367. CASE_IGNORE,
  1368. CASE_IGNORE,
  1369. /*    DC4        NAK        SYN        ETB    */
  1370. CASE_IGNORE,
  1371. CASE_IGNORE,
  1372. CASE_IGNORE,
  1373. CASE_IGNORE,
  1374. /*    CAN        EM        SUB        ESC    */
  1375. CASE_IGNORE,
  1376. CASE_IGNORE,
  1377. CASE_IGNORE,
  1378. CASE_ESC,
  1379. /*    FS        GS        RS        US    */
  1380. CASE_IGNORE,
  1381. CASE_IGNORE,
  1382. CASE_IGNORE,
  1383. CASE_IGNORE,
  1384. /*    SP        !        "        #    */
  1385. CASE_ESC_IGNORE,
  1386. CASE_ESC_IGNORE,
  1387. CASE_ESC_IGNORE,
  1388. CASE_ESC_IGNORE,
  1389. /*    $        %        &        '    */
  1390. CASE_ESC_IGNORE,
  1391. CASE_ESC_IGNORE,
  1392. CASE_ESC_IGNORE,
  1393. CASE_ESC_IGNORE,
  1394. /*    (        )        *        +    */
  1395. CASE_ESC_IGNORE,
  1396. CASE_ESC_IGNORE,
  1397. CASE_ESC_IGNORE,
  1398. CASE_ESC_IGNORE,
  1399. /*    ,        -        .        /    */
  1400. CASE_ESC_IGNORE,
  1401. CASE_ESC_IGNORE,
  1402. CASE_ESC_IGNORE,
  1403. CASE_ESC_IGNORE,
  1404. /*    0        1        2        3    */
  1405. CASE_GSETS,
  1406. CASE_GSETS,
  1407. CASE_GSETS,
  1408. CASE_GROUND_STATE,
  1409. /*    4        5        6        7    */
  1410. CASE_GROUND_STATE,
  1411. CASE_GROUND_STATE,
  1412. CASE_GROUND_STATE,
  1413. CASE_GROUND_STATE,
  1414. /*    8        9        :        ;    */
  1415. CASE_GROUND_STATE,
  1416. CASE_GROUND_STATE,
  1417. CASE_GROUND_STATE,
  1418. CASE_GROUND_STATE,
  1419. /*    <        =        >        ?    */
  1420. CASE_GROUND_STATE,
  1421. CASE_GROUND_STATE,
  1422. CASE_GROUND_STATE,
  1423. CASE_GROUND_STATE,
  1424. /*    @        A        B        C    */
  1425. CASE_GROUND_STATE,
  1426. CASE_GSETS,
  1427. CASE_GSETS,
  1428. CASE_GROUND_STATE,
  1429. /*    D        E        F        G    */
  1430. CASE_GROUND_STATE,
  1431. CASE_GROUND_STATE,
  1432. CASE_GROUND_STATE,
  1433. CASE_GROUND_STATE,
  1434. /*    H        I        J        K    */
  1435. CASE_GROUND_STATE,
  1436. CASE_GROUND_STATE,
  1437. CASE_GROUND_STATE,
  1438. CASE_GROUND_STATE,
  1439. /*    L        M        N        O    */
  1440. CASE_GROUND_STATE,
  1441. CASE_GROUND_STATE,
  1442. CASE_GROUND_STATE,
  1443. CASE_GROUND_STATE,
  1444. /*    P        Q        R        S    */
  1445. CASE_GROUND_STATE,
  1446. CASE_GROUND_STATE,
  1447. CASE_GROUND_STATE,
  1448. CASE_GROUND_STATE,
  1449. /*    T        U        V        W    */
  1450. CASE_GROUND_STATE,
  1451. CASE_GROUND_STATE,
  1452. CASE_GROUND_STATE,
  1453. CASE_GROUND_STATE,
  1454. /*    X        Y        Z        [    */
  1455. CASE_GROUND_STATE,
  1456. CASE_GROUND_STATE,
  1457. CASE_GROUND_STATE,
  1458. CASE_GROUND_STATE,
  1459. /*    \        ]        ^        _    */
  1460. CASE_GROUND_STATE,
  1461. CASE_GROUND_STATE,
  1462. CASE_GROUND_STATE,
  1463. CASE_GROUND_STATE,
  1464. /*    `        a        b        c    */
  1465. CASE_GROUND_STATE,
  1466. CASE_GROUND_STATE,
  1467. CASE_GROUND_STATE,
  1468. CASE_GROUND_STATE,
  1469. /*    d        e        f        g    */
  1470. CASE_GROUND_STATE,
  1471. CASE_GROUND_STATE,
  1472. CASE_GROUND_STATE,
  1473. CASE_GROUND_STATE,
  1474. /*    h        i        j        k    */
  1475. CASE_GROUND_STATE,
  1476. CASE_GROUND_STATE,
  1477. CASE_GROUND_STATE,
  1478. CASE_GROUND_STATE,
  1479. /*    l        m        n        o    */
  1480. CASE_GROUND_STATE,
  1481. CASE_GROUND_STATE,
  1482. CASE_GROUND_STATE,
  1483. CASE_GROUND_STATE,
  1484. /*    p        q        r        s    */
  1485. CASE_GROUND_STATE,
  1486. CASE_GROUND_STATE,
  1487. CASE_GROUND_STATE,
  1488. CASE_GROUND_STATE,
  1489. /*    t        u        v        w    */
  1490. CASE_GROUND_STATE,
  1491. CASE_GROUND_STATE,
  1492. CASE_GROUND_STATE,
  1493. CASE_GROUND_STATE,
  1494. /*    x        y        z        {    */
  1495. CASE_GROUND_STATE,
  1496. CASE_GROUND_STATE,
  1497. CASE_GROUND_STATE,
  1498. CASE_GROUND_STATE,
  1499. /*    |        }        ~        DEL    */
  1500. CASE_GROUND_STATE,
  1501. CASE_GROUND_STATE,
  1502. CASE_GROUND_STATE,
  1503. CASE_GROUND_STATE,
  1504. };
  1505. RAZZLE!DAZZLE
  1506. fi    # End VTparsetable.c
  1507. if test -f button.c
  1508. then
  1509.     echo shar: will not overwrite existing file "'button.c'"
  1510. else
  1511. echo 'x - button.c'
  1512. cat << \RAZZLE!DAZZLE > button.c
  1513. /*
  1514.  *    $Source: /u1/X/xterm/RCS/button.c,v $
  1515.  *    $Header: button.c,v 10.103 86/12/02 09:49:20 swick Exp $
  1516.  */
  1517.  
  1518. #include <X/mit-copyright.h>
  1519.  
  1520. /* Copyright    Massachusetts Institute of Technology    1984, 1985    */
  1521. /*
  1522. button.c    Handles button events in the terminal emulator.
  1523.         does cut/paste operations, change modes via menu,
  1524.         passes button events through to some applications.
  1525.                 J. Gettys.
  1526. */
  1527. #ifndef lint
  1528. static char sccs_id[] = "@(#)button.c\tX10/6.6B\t12/26/86";
  1529. #endif    lint
  1530. #include <stdio.h>
  1531. #include <signal.h>
  1532. #include <setjmp.h>
  1533. #include <ctype.h>
  1534. #include <X/Xlib.h>
  1535. #include "scrollbar.h"
  1536. #include "ptyx.h"
  1537. #include "data.h"
  1538. #include "error.h"
  1539. #ifdef MODEMENU
  1540. #include "menu.h"
  1541. #endif MODEMENU
  1542.  
  1543. #define NBUTS 3
  1544. #define DIRS 2
  1545. #define UP 1
  1546. #define DOWN 0
  1547. #define SHIFTS 8        /* three keys, so eight combinations */
  1548. #define    Coordinate(r,c)        ((r) * ncols + (c))
  1549.  
  1550. char *GetRestOfLine();
  1551. char *SaveText();
  1552. extern UnSaltText();
  1553. extern StartCut();
  1554. extern ReExecute();
  1555. extern EditorDown();
  1556.  
  1557. extern ButtonUp();
  1558. extern DownButtonDown();
  1559. extern MiddleButtonDown();
  1560. extern UpButtonDown();
  1561. extern ModeMenu();
  1562. extern char *xterm_name;
  1563. extern Bogus(), Silence();
  1564. extern GINbutton();
  1565. /* due to LK201 limitations, not all of the below are actually possible */
  1566. static int (*bfunc[SHIFTS][DIRS][NBUTS])() = {
  1567. /*    left        middle        right    */
  1568.     EditorDown,    EditorDown,    EditorDown,    /* down    |      */
  1569.     Silence,    Silence,    Silence,    /* up    |no shift */
  1570.  
  1571.     ReExecute,    StartCut,    Silence,    /* down |      */
  1572.     Silence,    Silence,    UnSaltText,    /* up    |shift      */
  1573.  
  1574.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1575.     Silence,    Silence,    Silence,    /* up    |meta      */
  1576.  
  1577.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1578.     Silence,    Silence,    Silence,    /* up    |meta shift */
  1579.  
  1580.     ModeMenu,    ModeMenu,    ModeMenu,    /* down    |      */
  1581.     Silence,    Silence,    Silence,    /* up    |control  */
  1582.  
  1583.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1584.     Silence,    Silence,    Silence,    /* up    |ctl shift */
  1585.  
  1586.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1587.     Silence,    Silence,    Silence,    /* up    |no shift */
  1588.  
  1589.     Bogus,        Bogus,        Bogus,        /* down    | control  */
  1590.     Silence,    Silence,    Silence        /* up    |meta shift*/
  1591.  
  1592. };    /* button, shift keys, and direction */
  1593. static int (*tfunc[SHIFTS][DIRS][NBUTS])() = {
  1594. /*    left        middle        right    */
  1595.     ModeMenu,    ModeMenu,    ModeMenu,    /* down    |      */
  1596.     Silence,    Silence,    Silence,    /* up    |no shift */
  1597.  
  1598.     ModeMenu,    ModeMenu,    ModeMenu,    /* down |      */
  1599.     Silence,    Silence,    Silence,    /* up    |shift      */
  1600.  
  1601.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1602.     Silence,    Silence,    Silence,    /* up    |meta      */
  1603.  
  1604.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1605.     Silence,    Silence,    Silence,    /* up    |meta shift */
  1606.  
  1607.     ModeMenu,    ModeMenu,    ModeMenu,    /* down    |      */
  1608.     Silence,    Silence,    Silence,    /* up    |control  */
  1609.  
  1610.     ModeMenu,    ModeMenu,    ModeMenu,    /* down    |      */
  1611.     Silence,    Silence,    Silence,    /* up    |ctl shift */
  1612.  
  1613.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1614.     Silence,    Silence,    Silence,    /* up    |no shift */
  1615.  
  1616.     Bogus,        Bogus,        Bogus,        /* down    | control  */
  1617.     Silence,    Silence,    Silence        /* up    |meta shift*/
  1618.  
  1619. };    /* button, shift keys, and direction */
  1620. static int (*scrollfunc[SHIFTS][DIRS][NBUTS])() = {
  1621. /*    left        middle        right    */
  1622.     UpButtonDown,    ModeMenu,    DownButtonDown,    /* down    |      */
  1623.     ButtonUp,    Silence,    ButtonUp,    /* up    |no shift */
  1624.  
  1625.     UpButtonDown,    ModeMenu,    DownButtonDown,    /* down |      */
  1626.     ButtonUp,    Silence,    ButtonUp,    /* up    |shift      */
  1627.  
  1628.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1629.     Silence,    Silence,    Silence,    /* up    |meta      */
  1630.  
  1631.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1632.     Silence,    Silence,    Silence,    /* up    |meta shift */
  1633.  
  1634.     UpButtonDown,    ModeMenu,    DownButtonDown,    /* down    |      */
  1635.     ButtonUp,    Silence,    ButtonUp,    /* up    |control  */
  1636.  
  1637.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1638.     Silence,    Silence,    Silence,    /* up    |ctl shift */
  1639.  
  1640.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1641.     Silence,    Silence,    Silence,    /* up    |no shift */
  1642.  
  1643.     Bogus,        Bogus,        Bogus,        /* down    | control  */
  1644.     Silence,    Silence,    Silence        /* up    |meta shift*/
  1645.  
  1646. };    /* button, shift keys, and direction */
  1647. static int (*Tbfunc[SHIFTS][DIRS][NBUTS])() = {
  1648. /*    left        middle        right    */
  1649.     GINbutton,    GINbutton,    GINbutton,    /* down    |      */
  1650.     Silence,    Silence,    Silence,    /* up    |no shift */
  1651.  
  1652.     GINbutton,    GINbutton,    GINbutton,    /* down |      */
  1653.     Silence,    Silence,    Silence,    /* up    |shift      */
  1654.  
  1655.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1656.     Silence,    Silence,    Silence,    /* up    |meta      */
  1657.  
  1658.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1659.     Silence,    Silence,    Silence,    /* up    |meta shift */
  1660.  
  1661.     ModeMenu,    ModeMenu,    ModeMenu,    /* down    |      */
  1662.     Silence,    Silence,    Silence,    /* up    |control  */
  1663.  
  1664.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1665.     Silence,    Silence,    Silence,    /* up    |ctl shift */
  1666.  
  1667.     Bogus,        Bogus,        Bogus,        /* down    |      */
  1668.     Silence,    Silence,    Silence,    /* up    |no shift */
  1669.  
  1670.     Bogus,        Bogus,        Bogus,        /* down    | control  */
  1671.     Silence,    Silence,    Silence        /* up    |meta shift*/
  1672.  
  1673. };    /* button, shift keys, and direction */
  1674.  
  1675. extern Terminal term;
  1676.  
  1677. static int crow, ccol;    /* cut row and column */
  1678. static int ccoord;
  1679. static int ncols;
  1680.  
  1681. HandleButtons(term, reply, pty)
  1682. register Terminal *term;
  1683. register XEvent *reply;
  1684. int pty;            /* file descriptor of pty */
  1685. {
  1686.     register Screen *screen = &term->screen;
  1687.     int (*bp)();
  1688.     int dir = DOWN;
  1689.     /* so table above will be nice, we change left to right */
  1690.     int button = 2 - ((XKeyOrButtonEvent *)reply)->detail & 0177; 
  1691.     int shift = KeyState(((XKeyOrButtonEvent *)reply)->detail);
  1692.  
  1693.     switch (reply->type) {
  1694.         case ButtonPressed:
  1695.             dir = DOWN;
  1696.             break;
  1697.         case ButtonReleased:
  1698.             dir = UP;
  1699.             break;
  1700.         default:
  1701.             break;
  1702.     }
  1703.     if(L_flag && !checklogin()) {    /* if login window, check for login */
  1704.         if(dir == DOWN)
  1705.             Bell();
  1706.         return;
  1707.     }
  1708.     bp = (screen->sb && (reply->window == screen->sb->bar ||
  1709.      GetButtonState(screen->sb) != BUTTON_NORMAL)) ?
  1710.      scrollfunc[shift][dir][button] :
  1711.      ((Titlebar(screen) && (reply->window == screen->title.tbar ||
  1712.      reply->window == screen->Ttitle.tbar)) ? tfunc[shift][dir][button] :
  1713.      ((reply->window == TWindow(screen)) ? Tbfunc[shift][dir][button] :
  1714.      bfunc[shift][dir][button]));
  1715.     if (bp != NULL)
  1716.         (*bp)(term, reply, pty);
  1717.     else
  1718.         Bell();
  1719. }
  1720.  
  1721. UnSaltText(term, reply, pty)
  1722. register Terminal *term;
  1723. register XKeyOrButtonEvent *reply;
  1724. int pty;            /* file descriptor of pty */
  1725. {
  1726.     char *line;
  1727.     int nbytes;
  1728.     register char *lag, *cp, *end;
  1729.  
  1730.     line = XFetchBytes(&nbytes);
  1731.     end = &line[nbytes];
  1732.     lag = line;
  1733.     for (cp = line; cp != end; cp++)
  1734.     {
  1735.         if (*cp != '\n') continue;
  1736.         *cp = '\r';
  1737.         write(pty, lag, cp - lag + 1);
  1738.         lag = cp + 1;
  1739.     }
  1740.     if (lag != end)
  1741.         write(pty, lag, end - lag);
  1742.     free (line);    /* free text from fetch */
  1743. }
  1744.  
  1745. ReExecute(term, reply, pty)
  1746. register XKeyOrButtonEvent *reply;
  1747. Terminal *term;
  1748. int pty;
  1749. {
  1750.     XKeyOrButtonEvent xevent;
  1751.     register XKeyOrButtonEvent *ev = &xevent;
  1752.     register Screen *screen = &term->screen;
  1753.     register int xrow, xcol, mask, cursor, ignore;
  1754.     register char *line;
  1755.     int row, col;
  1756.  
  1757.     cursor = screen->curs;
  1758.     if(!XGrabMouse(VWindow(screen), cursor,
  1759.      mask = ButtonReleased | EnterWindow | LeaveWindow | MouseMoved)) {
  1760.         Bell();
  1761.         return;
  1762.     }
  1763.     ncols = screen->max_col + 1;    /* needed by Coordinate() define */
  1764.     if(NearestRowCol(reply->y, reply->x, &crow, &ccol) ||
  1765.      crow > screen->max_row) {
  1766.         Bell();
  1767.         XUngrabMouse();
  1768.         return;
  1769.     }
  1770.     xrow = crow;
  1771.     xcol = ccol;
  1772.     crow++;
  1773.     ccol = 0;
  1774.     ccoord = Coordinate(crow, ccol);
  1775.     if (screen->cursor_state)
  1776.         HideCursor ();
  1777.     HiliteText(xrow, xcol, crow, 0, TRUE);
  1778.     ignore = FALSE;
  1779.     for( ; ; ) {
  1780.         XMaskEvent(mask, ev);
  1781.         switch(ev->type) {
  1782.          case ButtonReleased:
  1783.             if(xrow == crow - 1) {
  1784.                 line = GetRestOfLine(screen, xrow, xcol);
  1785.                 row = strlen(line);
  1786.                 write(pty, line, row);
  1787.                 line[row] = '\n';
  1788.                 XStoreBytes(line, row);
  1789.                 free (line);    /* free text from fetch */
  1790.                 HiliteText(xrow, xcol, crow, 0, FALSE);
  1791.             }
  1792.             XUngrabMouse();
  1793.             if (screen->cursor_set && !screen->cursor_state)
  1794.                 ShowCursor ();
  1795.             return;
  1796.          case LeaveWindow:
  1797.             if(ev->window != VWindow(screen))
  1798.                 break;
  1799.             if(xrow == crow - 1)
  1800.                 HiliteText(xrow, xcol, crow, 0, FALSE);
  1801.             xrow = crow;
  1802.             xcol = 0;
  1803.             XGrabMouse(VWindow(screen), cursor, mask & ~MouseMoved);
  1804.             ignore = TRUE;
  1805.             break;
  1806.          case EnterWindow:
  1807.             if(ev->window != VWindow(screen))
  1808.                 break;
  1809.             XGrabMouse(VWindow(screen), cursor, mask);
  1810.             ignore = FALSE;
  1811.                 /* drop through */
  1812.          case MouseMoved:
  1813.             if(ignore)
  1814.                 break;
  1815.             NearestRowCol(ev->y, ev->x, &row, &col);
  1816.             if(row != crow - 1) {
  1817.                 if(xrow == crow - 1)
  1818.                     HiliteText(xrow, xcol, crow, 0, FALSE);
  1819.             } else if(xrow == row)
  1820.                 TrackText(xrow, xcol, row, col);
  1821.             else
  1822.                 HiliteText(row, col, crow, 0, TRUE);
  1823.             xrow = row;
  1824.             xcol = col;
  1825.             break;
  1826.         }
  1827.     }
  1828. }
  1829.     
  1830. char *GetRestOfLine(screen, row, col)
  1831. register Screen *screen;
  1832. register int row, col;
  1833. {
  1834.     char *line;
  1835.     int i;
  1836.  
  1837.     i = Length(screen, row, col, screen->max_col);
  1838.     if((line = (char *)malloc(i + 2)) == NULL)
  1839.         SysError(ERROR_BMALLOC);
  1840.     SaveText(screen, row, col, screen->max_col, line);
  1841.     line[i] = '\r';
  1842.     line[i+1] = '\0';
  1843.     return(line);
  1844. }
  1845.  
  1846. StartCut(term, reply, pty)
  1847. register XKeyOrButtonEvent *reply;
  1848. Terminal *term;
  1849. int pty;
  1850. {
  1851.     XKeyOrButtonEvent xevent;
  1852.     register XKeyOrButtonEvent *ev = &xevent;
  1853.     register Screen *screen = &term->screen;
  1854.     register int xrow, xcol, mask, cursor, ignore;
  1855.     int row, col;
  1856.  
  1857.     cursor = screen->curs;
  1858.     if(!XGrabMouse(VWindow(screen), cursor,
  1859.      mask = ButtonReleased | EnterWindow | LeaveWindow | MouseMoved)) {
  1860.         Bell();
  1861.         return;
  1862.     }
  1863.     ncols = screen->max_col + 1;    /* needed by Coordinate() define */
  1864.     NearestRowCol(reply->y, reply->x, &crow, &ccol);
  1865.     ccoord = Coordinate(crow, ccol);
  1866.     xrow = crow;
  1867.     xcol = ccol;
  1868.     ignore = FALSE;
  1869.     if (screen->cursor_state)
  1870.         HideCursor ();
  1871.     for( ; ; ) {
  1872.         XMaskEvent(mask, ev);
  1873.         switch(ev->type) {
  1874.          case ButtonReleased:
  1875.             if(!ignore) {
  1876.                 row = crow;
  1877.                 col = ccol; /* SaltTextAway may alter these */
  1878.                 SaltTextAway(term, xrow, xcol, pty);
  1879.             }
  1880.             HiliteText(row, col, xrow, xcol, FALSE);
  1881.             XUngrabMouse();
  1882.             if (screen->cursor_set && !screen->cursor_state)
  1883.                 ShowCursor ();
  1884.             return;
  1885.          case LeaveWindow:
  1886.             if(ev->window != VWindow(screen))
  1887.                 break;
  1888.             HiliteText(crow, ccol, xrow, xcol, FALSE);
  1889.             xrow = crow;
  1890.             xcol = ccol;
  1891.             XGrabMouse(VWindow(screen), cursor, mask & ~MouseMoved);
  1892.             ignore = TRUE;
  1893.             break;
  1894.          case EnterWindow:
  1895.             if(ev->window != VWindow(screen))
  1896.                 break;
  1897.             XGrabMouse(VWindow(screen), cursor, mask);
  1898.             ignore = FALSE;
  1899.                 /* drop through */
  1900.          case MouseMoved:
  1901.             if(ignore)
  1902.                 break;
  1903.             NearestRowCol(ev->y, ev->x, &row, &col);
  1904.             if(row != xrow || col != xcol) {
  1905.                 TrackText(xrow, xcol, row, col);
  1906.                 xrow = row;
  1907.                 xcol = col;
  1908.             }
  1909.             break;
  1910.         }
  1911.     }
  1912. }
  1913.  
  1914. int NearestRowCol(y, x, r, c)
  1915. register int y, x;
  1916. int *r, *c;
  1917. {
  1918.     register Screen *screen = &term.screen;
  1919.     register row, col, i;
  1920.     register char *ch;
  1921.     register int passed_eol = FALSE;
  1922.  
  1923.     if((row = (y - screen->border - Titlebar(screen)) / FontHeight(screen))
  1924.      < 0)
  1925.         row = 0;
  1926.     else if(row > screen->max_row)
  1927.         row = screen->max_row;
  1928.     i = FontWidth(screen);
  1929.     if((col = (x - screen->border + (i / 3)) / i) < 0)
  1930.         col = 0;
  1931.     else if(col > screen->max_col + 1)
  1932.         col = screen->max_col + 1;
  1933.     if(col > 0) {
  1934.         for(i = screen->max_col,
  1935.          ch = screen->buf[2 * (row + screen->topline)] + i ;
  1936.          i > 0 && *ch == 0 ; ch--, i--);
  1937.         if(col > i + 1) {
  1938.             col = 0;
  1939.             row++;
  1940.             passed_eol = TRUE;
  1941.         }
  1942.     }
  1943.     *r = row;
  1944.     *c = col;
  1945.     return(passed_eol);
  1946. }
  1947.  
  1948. TrackText(frow, fcol, trow, tcol)
  1949. register int frow, fcol, trow, tcol;
  1950. {
  1951.     register int f, t;
  1952.  
  1953.     f = Coordinate(frow, fcol);
  1954.     t = Coordinate(trow, tcol);
  1955.     if(f == t)
  1956.         return;
  1957.     if(f > ccoord) {
  1958.         if(t < ccoord) {
  1959.             HiliteText(crow, ccol, frow, fcol, FALSE);
  1960.             HiliteText(trow, tcol, crow, ccol, TRUE);
  1961.         } else if(t > f)
  1962.             HiliteText(frow, fcol, trow, tcol, TRUE);
  1963.         else
  1964.             HiliteText(trow, tcol, frow, fcol, FALSE);
  1965.     } else {
  1966.         if(t > ccoord) {
  1967.             HiliteText(frow, fcol, crow, ccol, FALSE);
  1968.             HiliteText(crow, ccol, trow, tcol, TRUE);
  1969.         } else if(t < f)
  1970.             HiliteText(trow, tcol, frow, fcol, TRUE);
  1971.         else
  1972.             HiliteText(frow, fcol, trow, tcol, FALSE);
  1973.     }
  1974. }
  1975.  
  1976. HiliteText(frow, fcol, trow, tcol, hilite)
  1977. register int frow, fcol, trow, tcol;
  1978. int hilite;
  1979. {
  1980.     register Screen *screen = &term.screen;
  1981.     register int i, j;
  1982.  
  1983.     if((i = Coordinate(frow, fcol)) == (j = Coordinate(trow, tcol)))
  1984.         return;
  1985.     else if(i > j) {
  1986.         i = frow;
  1987.         j = fcol;
  1988.         frow = trow;
  1989.         fcol = tcol;
  1990.         trow = i;
  1991.         tcol = j;
  1992.     }
  1993.     if(hilite) {
  1994.         i = screen->foreground;
  1995.         screen->foreground = screen->background;
  1996.         screen->background = i;
  1997.     }
  1998.     if(frow != trow) {    /* do multiple rows */
  1999.         if((i = screen->max_col - fcol + 1) > 0) {    /* first row */
  2000.             XPixSet(VWindow(screen), fcol * FontWidth(screen) +
  2001.              screen->border, frow * FontHeight(screen) +
  2002.              screen->border + Titlebar(screen), i * FontWidth(screen),
  2003.              FontHeight(screen), screen->background);
  2004.             ScrnRefresh(screen, frow, fcol, 1, i);
  2005.         }
  2006.         if((i = trow - frow - 1) > 0) {            /* middle rows*/
  2007.             j = screen->max_col + 1;
  2008.             XPixSet(VWindow(screen), screen->border, (frow + 1) *
  2009.              FontHeight(screen) + screen->border + Titlebar(screen),
  2010.              j * FontWidth(screen), i * FontHeight(screen),
  2011.              screen->background);
  2012.             ScrnRefresh(screen, frow + 1, 0, i, j);
  2013.         }
  2014.         if(tcol > 0 && trow <= screen->max_row) {    /* last row */
  2015.             XPixSet(VWindow(screen), screen->border, trow *
  2016.              FontHeight(screen) + screen->border + Titlebar(screen),
  2017.              tcol * FontWidth(screen), FontHeight(screen),
  2018.              screen->background);
  2019.             ScrnRefresh(screen, trow, 0, 1, tcol);
  2020.         }
  2021.     } else {        /* do single row */
  2022.         i = tcol - fcol;
  2023.         XPixSet(VWindow(screen), fcol* FontWidth(screen) + screen->border,
  2024.          frow * FontHeight(screen) + screen->border + Titlebar(screen),
  2025.          i * FontWidth(screen), FontHeight(screen), screen->background);
  2026.         ScrnRefresh(screen, frow, fcol, 1, tcol - fcol);
  2027.     }
  2028.     if(hilite) {
  2029.         i = screen->foreground;
  2030.         screen->foreground = screen->background;
  2031.         screen->background = i;
  2032.     }
  2033. }
  2034.  
  2035. SaltTextAway(term, row, col, pty)
  2036. Terminal *term;
  2037. register row, col;
  2038. int pty;
  2039. {
  2040.     register Screen *screen = &term->screen;
  2041.     register int i, j = 0;
  2042.     register char *str;        /* string to be saved */
  2043.     char *line, *lp;
  2044.  
  2045.     /* first order of business is to guarantee that crow,ccol is before */
  2046.     /* row,col. */
  2047.     if ( row == crow ) {        /* must exchange as pairs */
  2048.         if ( ccol > col ) {     /* may have to exchange columns */
  2049.             register int tmp;
  2050.             tmp = ccol; ccol = col; col = tmp;
  2051.         }
  2052.     }
  2053.     else {
  2054.         if ( crow > row ) {    /* may have to exchange row and col */
  2055.             register int tmp;
  2056.             tmp = ccol; ccol = col; col = tmp;
  2057.             tmp = crow; crow = row; row = tmp;
  2058.         }
  2059.     }
  2060.         
  2061.     if (ccol < 0) ccol = 0;
  2062.     else if (ccol > screen->max_col) { crow++; ccol = 0; }
  2063.     if (crow < 0) crow = ccol = 0;
  2064.     else if (crow > screen->max_row) { crow = screen->max_row; ccol = 0; }
  2065.  
  2066.     if (row > screen->max_row) { row = screen->max_row + 1 ; col = 0; }
  2067.     else if (--col > screen->max_col) col = screen->max_col;
  2068.  
  2069.     /* first we need to know how long the string is before we can save it*/
  2070.  
  2071.     if ( row == crow ) j = Length(screen, crow, ccol, col);
  2072.     else {    /* two cases, cut is on same line, cut spans multiple lines */
  2073.         j += Length(screen, crow, ccol, screen->max_col) + 1;
  2074.         for(i = crow + 1; i < row; i++) 
  2075.             j += Length(screen, i, 0, screen->max_col) + 1;
  2076.         if (col >= 0)
  2077.             j += Length(screen, row, 0, col);
  2078.     }
  2079.     
  2080.     /* now get some memory to save it in */
  2081.  
  2082.     if((line = (char *)malloc(j + 1)) == NULL)
  2083.         SysError(ERROR_BMALLOC2);
  2084.     line[j] = '\0';        /* make sure it is null terminated */
  2085.     lp = line;        /* lp points to where to save the text */
  2086.     if ( row == crow ) lp = SaveText(screen, row, ccol, col, lp);
  2087.     else {
  2088.         lp = SaveText(screen, crow, ccol, screen->max_col, lp);
  2089.         *lp ++ = '\n';    /* put in newline at end of line */
  2090.         for(i = crow +1; i < row; i++) {
  2091.             lp = SaveText(screen, i, 0, screen->max_col, lp);
  2092.             *lp ++ = '\n';
  2093.             }
  2094.         if (col >= 0)
  2095.             lp = SaveText(screen, row, 0, col, lp);
  2096.     }
  2097.     *lp = '\0';        /* make sure we have end marked */
  2098.     
  2099.     XStoreBytes(line, j);
  2100.     free(line);
  2101. }
  2102.  
  2103. /* returns number of chars in line from scol to ecol out */
  2104. int Length(screen, row, scol, ecol)
  2105. register int row, scol, ecol;
  2106. register Screen *screen;
  2107. {
  2108.     register char *ch;
  2109.     int end = 0;
  2110.  
  2111.     ch = screen->buf[2 * (row + screen->topline)];
  2112.     while (ecol >= scol && ch[ecol] == 0)
  2113.         ecol--;
  2114.     return (ecol - scol + 1);
  2115. }
  2116.  
  2117. /* copies text into line, preallocated */
  2118. char *SaveText(screen, row, scol, ecol, lp)
  2119. int row;
  2120. int scol, ecol;
  2121. Screen *screen;
  2122. register char *lp;        /* pointer to where to put the text */
  2123. {
  2124.     register int i = 0;
  2125.     register char *ch = screen->buf[2 * (row + screen->topline)];
  2126.     register int c;
  2127.  
  2128.     if ((i = Length(screen, row, scol, ecol)) == 0) return(lp);
  2129.     ecol = scol + i;
  2130.     for (i = scol; i < ecol; i++) {
  2131.         if ((c = ch[i]) == 0)
  2132.             c = ' ';
  2133.         else if(c < ' ') {
  2134.             if(c == '\036')
  2135.                 c = '#';
  2136.             else
  2137.                 c += 0x5f;
  2138.         } else if(c == 0x7f)
  2139.             c = 0x5f;
  2140.         *lp++ = c;
  2141.     }
  2142.     return(lp);
  2143. }
  2144.  
  2145. EditorDown (term, reply, pty)
  2146. Terminal *term;
  2147. register XKeyOrButtonEvent *reply;
  2148. int pty;            /* file descriptor of pty */
  2149. {
  2150.     register Screen *screen = &term->screen;
  2151.     char line[6];
  2152.     register unsigned row, col;
  2153.     int button; 
  2154.  
  2155.     if (!screen->send_mouse_pos) {
  2156.         Bell();
  2157.         return;
  2158.     }
  2159.     button = 2 - reply->detail & 0177; 
  2160.     row = (reply->y - screen->border - Titlebar(screen)) / FontHeight(screen);
  2161.     col = (reply->x - screen->border) / FontWidth(screen);
  2162.     strcpy(line, "\033[M");
  2163.     line[3] = ' ' + button;
  2164.     line[4] = ' ' + col + 1;
  2165.     line[5] = ' ' + row + 1;
  2166.     write(pty, line, 6);
  2167. }
  2168.  
  2169. #ifdef MODEMENU
  2170. #define    MAXWINDOWMENU    64
  2171. #define    XTERMMENU    0
  2172. #define    VTMENU        1
  2173. #define    TEKMENU        2
  2174. #define    SCROLLBARMENU    3
  2175. #ifndef NOWINDOWMENU
  2176. #define    WINDOWMENU    4
  2177. #define    NMENUS        5
  2178. #else NOWINDOWMENU
  2179. #define    NMENUS        4
  2180. #endif NOWINDOWMENU
  2181.  
  2182. static Menu *menus[NMENUS];
  2183. #ifndef NOWINDOWMENU
  2184. static char *namebuf[MAXWINDOWMENU + 1];
  2185. static char *wname;
  2186. static Window windows[MAXWINDOWMENU];
  2187. #endif NOWINDOWMENU
  2188.  
  2189. ModeMenu(term, reply, pty)
  2190. Terminal *term;
  2191. register XKeyOrButtonEvent *reply;
  2192. int pty;            /* file descriptor of pty */
  2193. {
  2194.     register Screen *screen = &term->screen;
  2195.     register Menu *menu;
  2196.     register int type, item;
  2197.     static int inited;
  2198.     extern TekLink *TekRefresh;
  2199.     extern int xeventpass();
  2200.     extern Menu *setupmenu(), *Tsetupmenu(), *xsetupmenu();
  2201. #ifndef NOWINDOWMENU
  2202.     extern Menu *wsetupmenu();
  2203. #endif NOWINDOWMENU
  2204.     extern Menu *ssetupmenu();
  2205.  
  2206.     if((reply->window == screen->title.tbar || reply->window ==
  2207.      screen->Ttitle.tbar) && InTitle(screen, reply->window,
  2208.      reply->x))
  2209.         return;
  2210.     if(!inited) {
  2211.         extern Pixmap Gray_Tile;
  2212.         extern Cursor Menu_DefaultCursor;
  2213.         extern char *Menu_DefaultFont;
  2214.         extern FontInfo *Menu_DefaultFontInfo;
  2215.  
  2216.         inited++;
  2217.         Gray_Tile = screen->graybordertile;
  2218.         InitMenu(xterm_name);
  2219.         Menu_DefaultCursor = screen->arrow;
  2220.         if(strcmp(Menu_DefaultFont, f_t) == 0)
  2221.             Menu_DefaultFontInfo = screen->titlefont;
  2222.     }
  2223.     if((reply->detail & 0177) == LeftButton)
  2224.         type = XTERMMENU;
  2225.     else if((reply->detail & 0177) == RightButton)
  2226. #ifndef NOWINDOWMENU
  2227.         type = WINDOWMENU;
  2228. #else NOWINDOWMENU
  2229.         {
  2230.             Bell();
  2231.             return;
  2232.         }
  2233. #endif NOWINDOWMENU
  2234.     else if(reply->window == VWindow(screen) || reply->window ==
  2235.      screen->title.tbar)
  2236.         type = VTMENU;
  2237.     else if(reply->window == TWindow(screen) || reply->window ==
  2238.      screen->Ttitle.tbar)
  2239.         type = TEKMENU;
  2240.     else
  2241.         type = SCROLLBARMENU;
  2242.     switch(type) {
  2243.      case XTERMMENU:
  2244.         if((menu = xsetupmenu(&menus[XTERMMENU])) == NULL)
  2245.             return;
  2246.         break;
  2247.      case VTMENU:
  2248.         if((menu = setupmenu(&menus[VTMENU])) == NULL)
  2249.             return;
  2250.         break;
  2251. #ifndef NOWINDOWMENU
  2252.      case WINDOWMENU:
  2253.         wname = (reply->window == screen->title.tbar || reply->window
  2254.          == VWindow(screen)) ? screen->winname : screen->Twinname;
  2255.         if((menu = wsetupmenu(&menus[WINDOWMENU])) == NULL)
  2256.             return;
  2257.         break;
  2258. #endif NOWINDOWMENU
  2259.      case TEKMENU:
  2260.         if((menu = Tsetupmenu(&menus[TEKMENU])) == NULL)
  2261.             return;
  2262.         screen->waitrefresh = TRUE;
  2263.         break;
  2264.      case SCROLLBARMENU:
  2265.         if((menu = ssetupmenu(&menus[SCROLLBARMENU])) == NULL)
  2266.             return;
  2267.         break;
  2268.     }
  2269.     /*
  2270.      * Make the window entry and leaving routines holdoff on setting
  2271.      * the timer and on selecting or unselecting any windows.  Then
  2272.      * set the select mode manually.
  2273.      */
  2274.     screen->holdoff = TRUE;
  2275.     SetMenuEventHandler(menu, xeventpass);
  2276.     item = TrackMenu(menu, reply);
  2277.     menusync();
  2278.     screen->waitrefresh = FALSE;
  2279.     screen->timer = 0;
  2280.     screen->holdoff = FALSE;
  2281.     reselectwindow(screen);
  2282.  
  2283.     if (item < 0) {
  2284.         if(type == TEKMENU && TekRefresh)
  2285.             dorefresh();
  2286. #ifndef NOWINDOWMENU
  2287.         else if(type == WINDOWMENU)
  2288.             wfree(menu);
  2289. #endif NOWINDOWMENU
  2290.         return;
  2291.     }
  2292.     switch(type) {
  2293.      case XTERMMENU:
  2294.         xdomenufunc(item);
  2295.         break;
  2296.      case VTMENU:
  2297.         domenufunc(item);
  2298.         break;
  2299. #ifndef NOWINDOWMENU
  2300.      case WINDOWMENU:
  2301.         wdomenufunc(item);
  2302.         wfree(menu);
  2303.         break;
  2304. #endif NOWINDOWMENU
  2305.      case TEKMENU:
  2306.         Tdomenufunc(item);
  2307.         break;
  2308.      case SCROLLBARMENU:
  2309.         sdomenufunc(item);
  2310.         break;
  2311.     }
  2312. }
  2313.  
  2314. menusync()
  2315. {
  2316.     XEvent ev;
  2317.  
  2318.     XSync(0);
  2319.     while(QLength() > 0) {
  2320.         XNextEvent(&ev);
  2321.         xeventpass(&ev);
  2322.     }
  2323. }
  2324.  
  2325. #define    XMENU_TITLE    0
  2326. #define XMENU_ACTIVEICON (XMENU_TITLE+1)
  2327. #define XMENU_ALLOWICONINPUT (XMENU_ACTIVEICON+1)
  2328. #define    XMENU_AUTORAISE    (XMENU_ALLOWICONINPUT+1)
  2329. #define    XMENU_VISUALBELL (XMENU_AUTORAISE+1)
  2330. #define    XMENU_DEICONWARP (XMENU_VISUALBELL+1)
  2331. #define    XMENU_LOG    (XMENU_DEICONWARP+1)
  2332. #define    XMENU_LINE    (XMENU_LOG+1)
  2333. #define    XMENU_REDRAW    (XMENU_LINE+1)
  2334. #define    XMENU_RESUME    (XMENU_REDRAW+1)
  2335. #define    XMENU_SUSPEND    (XMENU_RESUME+1)
  2336. #define    XMENU_INTR    (XMENU_SUSPEND+1)
  2337. #define    XMENU_HANGUP    (XMENU_INTR+1)
  2338. #define    XMENU_TERM    (XMENU_HANGUP+1)
  2339. #define    XMENU_KILL    (XMENU_TERM+1)
  2340.  
  2341. static char *xtext[] = {
  2342.     "Title Bar(s)",
  2343.     "Active Icon",
  2344.     "Allow Icon Input",
  2345.     "Auto Raise",
  2346.     "Visual Bell",
  2347.     "Deiconify Warp",
  2348.     "Logging",
  2349.     "-",
  2350.     "Redraw",
  2351.     "Continue",
  2352.     "Suspend",
  2353.     "Interrupt",
  2354.     "Hangup",
  2355.     "Terminate",
  2356.     "Kill",
  2357.     0,
  2358. };
  2359.  
  2360. static int xauto;
  2361. static int xbell;
  2362. static int xdeiconwarp;
  2363. static int xlog;
  2364. static int xtbar;
  2365. static int xactive_icon;
  2366. static int xallow_iconinput;
  2367.  
  2368. Menu *xsetupmenu(menu)
  2369. register Menu **menu;
  2370. {
  2371.     register Screen *screen = &term.screen;
  2372.     register char **cp;
  2373.     register int i;
  2374.  
  2375.     if (*menu == NULL) {
  2376.         if ((*menu = NewMenu("xterm X10/6.6B", re_verse)) == NULL)
  2377.             return(NULL);
  2378.         for(cp = xtext ; *cp ; cp++)
  2379.             AddMenuItem(*menu, *cp);
  2380.         if(xtbar = (Titlebar(screen) > 0))
  2381.             CheckItem(*menu, XMENU_TITLE);
  2382.         if(xactive_icon = screen->active_icon)
  2383.             CheckItem(*menu, XMENU_ACTIVEICON);
  2384.         if(xallow_iconinput = (term.flags & ICONINPUT))
  2385.             CheckItem(*menu, XMENU_ALLOWICONINPUT);
  2386.         SetItemDisable(*menu, XMENU_ALLOWICONINPUT, !xactive_icon);
  2387.         if(xauto = screen->autoraise)
  2388.             CheckItem(*menu, XMENU_AUTORAISE);
  2389.         if(xbell = screen->visualbell)
  2390.             CheckItem(*menu, XMENU_VISUALBELL);
  2391.         if(xdeiconwarp = screen->deiconwarp)
  2392.             CheckItem(*menu, XMENU_DEICONWARP);
  2393.         if(xlog = screen->logging)
  2394.             CheckItem(*menu, XMENU_LOG);
  2395.         DisableItem(*menu, XMENU_LINE);
  2396.         if(screen->inhibit & I_LOG)
  2397.             DisableItem(*menu, XMENU_LOG);
  2398.         if(screen->inhibit & I_SIGNAL)
  2399.             for(i = XMENU_SUSPEND ; i <= XMENU_KILL ; i++)
  2400.                 DisableItem(*menu, i);
  2401.         return(*menu);
  2402.     }
  2403.     if (xtbar != (Titlebar(screen) > 0))
  2404.         SetItemCheck(*menu, XMENU_TITLE, (xtbar =
  2405.          (Titlebar(screen) > 0)));
  2406.     if (xactive_icon != screen->active_icon) {
  2407.         SetItemCheck(*menu, XMENU_ACTIVEICON,
  2408.                  (xactive_icon = screen->active_icon));
  2409.         SetItemDisable(*menu, XMENU_ALLOWICONINPUT, !xactive_icon);
  2410.     }
  2411.     if (xallow_iconinput != (term.flags & ICONINPUT))
  2412.         SetItemCheck(*menu, XMENU_ALLOWICONINPUT,
  2413.                  (xallow_iconinput = (term.flags & ICONINPUT)));
  2414.     if (xauto != screen->autoraise)
  2415.         SetItemCheck(*menu, XMENU_AUTORAISE, (xauto =
  2416.          screen->autoraise));
  2417.     if (xbell != screen->visualbell)
  2418.         SetItemCheck(*menu, XMENU_VISUALBELL, (xbell =
  2419.          screen->visualbell));
  2420.     if (xdeiconwarp != screen->deiconwarp)
  2421.         SetItemCheck(*menu, XMENU_DEICONWARP, (xdeiconwarp =
  2422.          screen->deiconwarp));
  2423.     if (xlog != screen->logging)
  2424.         SetItemCheck(*menu, XMENU_LOG, (xlog = screen->logging));
  2425.     return(*menu);
  2426. }
  2427.  
  2428. xdomenufunc(item)
  2429. int item;
  2430. {
  2431.     register Screen *screen = &term.screen;
  2432.  
  2433.     switch (item) {
  2434.     case XMENU_TITLE:
  2435.         if(Titlebar(screen)) {
  2436.                 screen->fullVwin.titlebar =
  2437.                 screen->fullTwin.titlebar = 0;
  2438.             if(VWindow(screen))
  2439.                 VTTitleHide();
  2440.             if(TWindow(screen))
  2441.                 TekTitleHide();
  2442.         } else {
  2443.                 screen->fullVwin.titlebar =
  2444.                 screen->fullTwin.titlebar = screen->titleheight;
  2445.             if(VWindow(screen))
  2446.                 VTTitleShow(FALSE);
  2447.             if(TWindow(screen))
  2448.                 TekTitleShow(FALSE);
  2449.         }
  2450.         break;
  2451.  
  2452.     case XMENU_ACTIVEICON:
  2453.         screen->active_icon = !screen->active_icon;
  2454.         if (screen->active_icon && !screen->fnt_icon) {
  2455.             FontInfo *fInfo = XOpenFont( f_i );
  2456.             screen->fnt_icon = fInfo->id;
  2457.             screen->iconVwin.f_width = fInfo->width;
  2458.             screen->iconVwin.f_height = fInfo->height;
  2459.         }
  2460.  
  2461.         if (screen->iconVwin.window) {
  2462.             SetIconSize( screen );
  2463.             XSelectInput( screen->iconVwin.window,
  2464.                       screen->active_icon
  2465.                   && (term.flags & ICONINPUT)
  2466.                     ? ICONWINDOWEVENTS | ICONINPUTEVENTS
  2467.                     : ICONWINDOWEVENTS );
  2468.         }
  2469.  
  2470.         if (screen->iconTwin.window) {
  2471.             TSetIconSize( screen );
  2472.             XSelectInput( screen->iconTwin.window,
  2473.                   screen->active_icon
  2474.                   && (term.flags & ICONINPUT)
  2475.                     ? TICONWINDOWEVENTS | ICONINPUTEVENTS
  2476.                     : TICONWINDOWEVENTS );
  2477.         }
  2478.  
  2479.         break;
  2480.  
  2481.     case XMENU_ALLOWICONINPUT:
  2482.         term.flags ^= ICONINPUT;
  2483.         if (screen->iconVwin.window)
  2484.             XSelectInput( screen->iconVwin.window,
  2485.                   screen->active_icon
  2486.                   && (term.flags & ICONINPUT)
  2487.                     ? ICONWINDOWEVENTS | ICONINPUTEVENTS
  2488.                     : ICONWINDOWEVENTS );
  2489.  
  2490.         if (screen->iconTwin.window)
  2491.             XSelectInput( screen->iconTwin.window,
  2492.                   screen->active_icon
  2493.                   && (term.flags & ICONINPUT)
  2494.                     ? TICONWINDOWEVENTS | ICONINPUTEVENTS
  2495.                     : TICONWINDOWEVENTS );
  2496.  
  2497.         break;
  2498.  
  2499.     case XMENU_AUTORAISE:
  2500.         screen->autoraise = !screen->autoraise;
  2501.         break;
  2502.  
  2503.     case XMENU_DEICONWARP:
  2504.         screen->deiconwarp = !screen->deiconwarp;
  2505.         break;
  2506.  
  2507.     case XMENU_VISUALBELL:
  2508.         screen->visualbell = !screen->visualbell;
  2509.         break;
  2510.  
  2511.     case XMENU_LOG:
  2512.         if(screen->logging)
  2513.             CloseLog(screen);
  2514.         else
  2515.             StartLog(screen);
  2516.         break;
  2517.  
  2518.     case XMENU_REDRAW:
  2519.         Redraw();
  2520.         break;
  2521.  
  2522.     case XMENU_RESUME:
  2523.         if(screen->pid > 1)
  2524.             killpg(getpgrp(screen->pid), SIGCONT);
  2525.         break;
  2526.  
  2527.     case XMENU_SUSPEND:
  2528.         if(screen->pid > 1)
  2529.             killpg(getpgrp(screen->pid), SIGTSTP);
  2530.         break;
  2531.  
  2532.     case XMENU_INTR:
  2533.         if(screen->pid > 1)
  2534.             killpg(getpgrp(screen->pid), SIGINT);
  2535.         break;
  2536.  
  2537.     case XMENU_HANGUP:
  2538.         if(screen->pid > 1)
  2539.             killpg(getpgrp(screen->pid), SIGHUP);
  2540.         break;
  2541.  
  2542.     case XMENU_TERM:
  2543.         if(screen->pid > 1)
  2544.             killpg(getpgrp(screen->pid), SIGTERM);
  2545.         break;
  2546.  
  2547.     case XMENU_KILL:
  2548.         if(screen->pid > 1)
  2549.             killpg(getpgrp(screen->pid), SIGKILL);
  2550.         break;
  2551.     }
  2552. }
  2553.  
  2554. #ifndef NOWINDOWMENU
  2555. Menu *wsetupmenu(menu)
  2556. register Menu **menu;
  2557. {
  2558.     register Window *cp, *wp;
  2559.     register char **np;
  2560.     register int i, j;
  2561.     Window win, *children;
  2562.     int nchildren;
  2563.     char *name;
  2564.     WindowInfo winfo;
  2565.  
  2566.     if(!XQueryTree(RootWindow, &win, &nchildren, &children))
  2567.         return(NULL);
  2568.     if(nchildren > MAXWINDOWMENU)
  2569.         nchildren = MAXWINDOWMENU;
  2570.     if ((*menu = NewMenu("Windows", re_verse)) == NULL) {
  2571.         free((char *)children);
  2572.         return(NULL);
  2573.     }
  2574.     np = namebuf;
  2575.     wp = windows;
  2576.     for(i = nchildren, j = 0, cp = children ; i > 0 ; cp++, i--) {
  2577.         if(!XQueryWindow(*cp, &winfo))
  2578.             goto failed;
  2579.         if(winfo.mapped != IsMapped)
  2580.             continue;
  2581.         if(!XFetchName(*cp, &name)) {
  2582. failed:
  2583.             free((char *)children);
  2584.             *np = NULL;
  2585.             wfree(*menu);
  2586.             return(NULL);
  2587.         }
  2588.         if(name == NULL)
  2589.             continue;
  2590.         AddMenuItem(*menu, *np++ = name);
  2591.         *wp++ = *cp;
  2592.         if(strcmp(wname, name) == 0)
  2593.             CheckItem(*menu, j);
  2594.         j++;
  2595.     }
  2596.     *np = NULL;
  2597.     free((char *)children);
  2598.     if(np > namebuf)
  2599.         return(*menu);
  2600.     DisposeMenu(*menu);
  2601.     return(NULL);
  2602. }
  2603.  
  2604. wdomenufunc(item)
  2605. int item;
  2606. {
  2607.     register Window w;
  2608.  
  2609.     if((w = windows[item]) != NULL)
  2610.         XRaiseWindow(w);
  2611. }
  2612.  
  2613. wfree(menu)
  2614. Menu *menu;
  2615. {
  2616.     register char **np;
  2617.  
  2618.     for(np = namebuf ; *np ; np++)
  2619.         free(*np);
  2620.     DisposeMenu(menu);
  2621. }
  2622. #endif NOWINDOWMENU
  2623.  
  2624. MenuNewCursor(cur)
  2625. register Cursor cur;
  2626. {
  2627.     register Menu **menu;
  2628.     register int i;
  2629.     extern Cursor Menu_DefaultCursor;
  2630.  
  2631.     Menu_DefaultCursor = cur;
  2632.     for(i = XTERMMENU, menu = menus ; i <= TEKMENU ; menu++, i++) {
  2633.         if(!*menu)
  2634.             continue;
  2635.         (*menu)->menuCursor = cur;
  2636.         if((*menu)->menuWindow)
  2637.             XDefineCursor((*menu)->menuWindow, cur);
  2638.     }
  2639. }
  2640. #else MODEMENU
  2641.  
  2642. ModeMenu(term, reply, pty)
  2643. Terminal *term;
  2644. register XKeyOrButtonEvent *reply;
  2645. int pty;            /* file descriptor of pty */
  2646. {
  2647.     register Screen *screen = &term->screen;
  2648.  
  2649.     if((reply->window == screen->title.tbar || reply->window ==
  2650.      screen->Ttitle.tbar) && InTitle(screen, reply->window,
  2651.      reply->x))
  2652.         return;
  2653.     Bell();
  2654. }
  2655. #endif MODEMENU
  2656.  
  2657. GINbutton(term, reply, pty)
  2658. Terminal *term;
  2659. XKeyOrButtonEvent *reply;
  2660. int pty;            /* file descriptor of pty */
  2661. {
  2662.     register Screen *screen = &term->screen;
  2663.     register int i;
  2664.  
  2665.     if(screen->TekGIN) {
  2666.         i = "rml"[reply->detail & 0xff];
  2667.         if(reply->detail & ShiftMask)
  2668.             i = toupper(i);
  2669.         TekEnqMouse(i | 0x80);    /* set high bit */
  2670.         TekGINoff();
  2671.     } else
  2672.         Bell();
  2673. }
  2674.  
  2675. Bogus(term, reply, pty)
  2676. Terminal *term;
  2677. XKeyOrButtonEvent *reply;
  2678. int pty;            /* file descriptor of pty */
  2679. {
  2680.     Bell();
  2681. }
  2682.  
  2683. Silence(term, reply, pty)
  2684. Terminal *term;
  2685. XKeyOrButtonEvent *reply;
  2686. int pty;            /* file descriptor of pty */
  2687. {
  2688. }
  2689. RAZZLE!DAZZLE
  2690. fi    # End button.c
  2691. if test -f cursor.c
  2692. then
  2693.     echo shar: will not overwrite existing file "'cursor.c'"
  2694. else
  2695. echo 'x - cursor.c'
  2696. cat << \RAZZLE!DAZZLE > cursor.c
  2697. /*
  2698.  *    $Source: /u1/X/xterm/RCS/cursor.c,v $
  2699.  *    $Header: cursor.c,v 10.100 86/12/01 14:43:54 jg Rel $
  2700.  */
  2701.  
  2702. #ifndef lint
  2703. static char *rcsid_cursor_c = "$Header: cursor.c,v 10.100 86/12/01 14:43:54 jg Rel $";
  2704. #endif    lint
  2705.  
  2706. #include <X/mit-copyright.h>
  2707.  
  2708. /* Copyright 1984, 1985   Massachusetts Institute of Technology        */
  2709.  
  2710. /* cursor.c */
  2711.  
  2712.  
  2713. #ifndef lint
  2714. static char sccs_id[] = "@(#)cursor.c\tX10/6.6B\t12/26/86";
  2715. #endif    lint
  2716.  
  2717. #include <X/Xlib.h>
  2718. #include <stdio.h>
  2719. #include <sys/ioctl.h>
  2720. #include "scrollbar.h"
  2721. #include "ptyx.h"
  2722.  
  2723. /*
  2724.  * Moves the cursor to the specified position, checking for bounds.
  2725.  * (this includes scrolling regions)
  2726.  * The origin is considered to be 0, 0 for this procedure.
  2727.  * In the status line, the cursor moves only horizontally.
  2728.  */
  2729. CursorSet(screen, row, col, flags)
  2730. register Screen    *screen;
  2731. register int    row, col;
  2732. unsigned    flags;
  2733. {
  2734.     register int maxr;
  2735.  
  2736.     col = (col < 0 ? 0 : col);
  2737.     screen->cur_col = (col <= screen->max_col ? col : screen->max_col);
  2738.     if(!screen->instatus) {
  2739.         maxr = screen->max_row;
  2740.         if (flags & ORIGIN) {
  2741.             row += screen->top_marg;
  2742.             maxr = screen->bot_marg;
  2743.         }
  2744.         row = (row < 0 ? 0 : row);
  2745.         screen->cur_row = (row <= maxr ? row : maxr);
  2746.     }
  2747.     screen->do_wrap = 0;
  2748. }
  2749.  
  2750. /*
  2751.  * moves the cursor left n, no wrap around
  2752.  */
  2753. CursorBack(screen, n)
  2754. register Screen    *screen;
  2755. int        n;
  2756. {
  2757.     register int i, j, k, rev;
  2758.     extern Terminal term;
  2759.  
  2760.     if((rev = (term.flags & (REVERSEWRAP | WRAPAROUND)) ==
  2761.      (REVERSEWRAP | WRAPAROUND)) && screen->do_wrap)
  2762.         n--;
  2763.     if ((screen->cur_col -= n) < 0) {
  2764.         if(rev) {
  2765.             if((i = (j = screen->max_col + 1) * screen->cur_row +
  2766.              screen->cur_col) < 0) {
  2767.                 k = j * (screen->max_row + 1);
  2768.                 i += ((-i) / k + 1) * k;
  2769.             }
  2770.             screen->cur_row = i / j;
  2771.             screen->cur_col = i % j;
  2772.         } else
  2773.             screen->cur_col = 0;
  2774.     }
  2775.     screen->do_wrap = 0;
  2776. }
  2777.  
  2778. /*
  2779.  * moves the cursor forward n, no wraparound
  2780.  */
  2781. CursorForward(screen, n)
  2782. register Screen    *screen;
  2783. int        n;
  2784. {
  2785.     screen->cur_col += n;
  2786.     if (screen->cur_col > screen->max_col)
  2787.         screen->cur_col = screen->max_col;
  2788.     screen->do_wrap = 0;
  2789. }
  2790.  
  2791. /* 
  2792.  * moves the cursor down n, no scrolling.
  2793.  * Won't pass bottom margin or bottom of screen.
  2794.  */
  2795. CursorDown(screen, n)
  2796. register Screen    *screen;
  2797. int        n;
  2798. {
  2799.     register int max;
  2800.  
  2801.     max = (screen->cur_row > screen->bot_marg ?
  2802.         screen->max_row : screen->bot_marg);
  2803.  
  2804.     screen->cur_row += n;
  2805.     if (screen->cur_row > max)
  2806.         screen->cur_row = max;
  2807.     screen->do_wrap = 0;
  2808. }
  2809.  
  2810. /* 
  2811.  * moves the cursor up n, no linestarving.
  2812.  * Won't pass top margin or top of screen.
  2813.  */
  2814. CursorUp(screen, n)
  2815. register Screen    *screen;
  2816. int        n;
  2817. {
  2818.     register int min;
  2819.  
  2820.     min = (screen->cur_row < screen->top_marg ?
  2821.         0 : screen->top_marg);
  2822.  
  2823.     screen->cur_row -= n;
  2824.     if (screen->cur_row < min)
  2825.         screen->cur_row = min;
  2826.     screen->do_wrap = 0;
  2827. }
  2828.  
  2829. /* 
  2830.  * Moves cursor down amount lines, scrolls if necessary.
  2831.  * Won't leave scrolling region. No carriage return.
  2832.  */
  2833. Index(screen, amount)
  2834. register Screen    *screen;
  2835. register int    amount;
  2836. {
  2837.     register int lines, j;
  2838.     register char *str;
  2839.     int n;
  2840.     XEvent ev;
  2841.  
  2842.     /* 
  2843.      * indexing when below scrolling region is cursor down.
  2844.      * if cursor high enough, no scrolling necessary.
  2845.      */
  2846.     if (screen->cur_row > screen->bot_marg
  2847.      || screen->cur_row + amount <= screen->bot_marg) {
  2848.         if(screen->pagemode)
  2849.             screen->pagecnt += amount;
  2850.         CursorDown(screen, amount);
  2851.         return;
  2852.     }
  2853.  
  2854.     CursorDown(screen, j = screen->bot_marg - screen->cur_row);
  2855.     amount -= j;
  2856.     if((lines = screen->bot_marg - screen->top_marg - screen->pageoverlap)
  2857.      <= 0)
  2858.         lines = 1;
  2859.     if(!screen->pagemode || (amount + screen->pagecnt) <= lines) {
  2860.         if(screen->pagemode)
  2861.             screen->pagecnt += amount;
  2862.         Scroll(screen, amount);
  2863.         return;
  2864.     }
  2865.     ioctl(screen->respond, TIOCSTOP, NULL);
  2866.     if(screen->cursor_state)
  2867.         HideCursor();
  2868.     if((j = lines - screen->pagecnt) > 0) {
  2869.         Scroll(screen, j);
  2870.         amount -= j;
  2871.     }
  2872.     do {
  2873.         if(screen->scroll_amt)
  2874.             FlushScroll(screen);
  2875.         j = FALSE;
  2876.         do {
  2877.             XNextEvent(&ev);
  2878.             switch((int)ev.type) {
  2879.              case KeyPressed:
  2880.                 str = XLookupMapping(&ev, &n);
  2881.                 if(n > 0) {
  2882.                     if(*str == '\r')
  2883.                         screen->pagecnt = (lines - 1);
  2884.                     else if(*str < ' ' || *str == '\177') {
  2885.                         screen->pagecnt = 0;
  2886.                         Input(&term.keyboard, screen,
  2887.                          &ev);
  2888.                         ioctl(screen->respond, TIOCSTOP,
  2889.                          NULL);
  2890.                     } else
  2891.                         screen->pagecnt = 0;
  2892.                 } else
  2893.                     screen->pagecnt = 0;
  2894.                 j = TRUE;
  2895.                 break;
  2896.              case ButtonPressed:
  2897.              case ButtonReleased:
  2898.                 screen->pagecnt = amount;
  2899.                 xeventpass(&ev);
  2900.                 if(!screen->pagemode) {
  2901.                     Scroll(screen, amount);
  2902.                     ioctl(screen->respond, TIOCSTART, NULL);
  2903.                     return;
  2904.                 }
  2905.                 break;
  2906.              default:
  2907.                 xeventpass(&ev);
  2908.                 break;
  2909.             }
  2910.         } while(!j);
  2911.         j = lines - screen->pagecnt;
  2912.         if(j > amount)
  2913.             j = amount;
  2914.         Scroll(screen, j);
  2915.         screen->pagecnt += j;
  2916.     } while((amount -= j) > 0);
  2917.     ioctl(screen->respond, TIOCSTART, NULL);
  2918. }
  2919.  
  2920. /*
  2921.  * Moves cursor up amount lines, reverse scrolls if necessary.
  2922.  * Won't leave scrolling region. No carriage return.
  2923.  */
  2924. RevIndex(screen, amount)
  2925. register Screen    *screen;
  2926. register int    amount;
  2927. {
  2928.     /*
  2929.      * reverse indexing when above scrolling region is cursor up.
  2930.      * if cursor low enough, no reverse indexing needed
  2931.      */
  2932.     if (screen->cur_row < screen->top_marg
  2933.      || screen->cur_row-amount >= screen->top_marg) {
  2934.         CursorUp(screen, amount);
  2935.         return;
  2936.     }
  2937.  
  2938.     RevScroll(screen, amount - (screen->cur_row - screen->top_marg));
  2939.     CursorUp(screen, screen->cur_row - screen->top_marg);
  2940. }
  2941.  
  2942. /*
  2943.  * Moves Cursor To First Column In Line
  2944.  */
  2945. CarriageReturn(screen)
  2946. register Screen *screen;
  2947. {
  2948.     screen->cur_col = 0;
  2949.     screen->do_wrap = 0;
  2950. }
  2951.  
  2952. /*
  2953.  * Save Cursor and Attributes
  2954.  */
  2955. CursorSave(term, sc)
  2956. register Terminal *term;
  2957. register SavedCursor *sc;
  2958. {
  2959.     register Screen *screen = &term->screen;
  2960.  
  2961.     sc->row = screen->cur_row;
  2962.     sc->col = screen->cur_col;
  2963.     sc->flags = term->flags;
  2964.     sc->curgl = screen->curgl;
  2965.     sc->curgr = screen->curgr;
  2966.     bcopy(screen->gsets, sc->gsets, sizeof(screen->gsets));
  2967. }
  2968.  
  2969. /*
  2970.  * Restore Cursor and Attributes
  2971.  */
  2972. CursorRestore(term, sc)
  2973. register Terminal *term;
  2974. register SavedCursor *sc;
  2975. {
  2976.     register Screen *screen = &term->screen;
  2977.  
  2978.     bcopy(sc->gsets, screen->gsets, sizeof(screen->gsets));
  2979.     screen->curgl = sc->curgl;
  2980.     screen->curgr = sc->curgr;
  2981.     term->flags &= ~(BOLD|INVERSE|UNDERLINE);
  2982.     term->flags |= sc->flags & (BOLD|INVERSE|UNDERLINE);
  2983.     CursorSet(screen, sc->row, sc->col, term->flags);
  2984. }
  2985. RAZZLE!DAZZLE
  2986. fi    # End cursor.c
  2987. echo '***** End of' xterm 6.6B - Part 3 of 7 '*****'
  2988. exit
  2989.  
  2990.